<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link rel="stylesheet" href="/css/sky/header.css" />
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/sky/index.css" th:href="@{/css/sky/index.css}"/>
<style type="text/css">
    th.orderby,.headerTr~tr{cursor: pointer;}
    .btn.btn-default.myOption{display: none;padding:3px 12px;color: #3b8cff;border: 1px solid #3b8cff;background-color: rgba(0,0,0,0);margin: 0 0 0 20px;}
    *{margin: 0;padding: 0;}
    .module-canvas{position: fixed; left: 0px; top: 0px; z-index: 50; background: rgba(0, 0, 0, 0.6); width: 100%; height: 100%;display: none;}
    .dialog-share{width: 530px; position: absolute;overflow: visible; z-index: 52; top: 50%;left: 50%;transform: translate(-50%,-50%); display: block; visibility: visible;border-radius: 4px;}
    .dialog-share .dialog-header {
        background: #f6f6f6;
        border-bottom: 0;
        border-top-left-radius: 4px;
        border-top-right-radius: 4px;
        height: 44px;
        line-height: 44px;
        font-weight: 200;
        position: relative;
        color: #333;
    }
    .table-hover img{
        height: 24px;
        margin-right: 10px;
    }

    a:hover{
        text-decoration: none;
    }
    .dialog .dialog-header h3 {
        position: relative;
        display: block;
        height: 42px;
        line-height: 42px;
        text-indent: 1em;
        font-size: 14px;
        font-weight: 700;
        color: #4d4d4d;
    }
    .dialog .dialog-header-title {
        display: block;
        margin-right: 50px;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-weight: 200;
    }
    .dialog .dialog-header-title .select-text {
        font-style: normal;
        cursor: text;
        color: #666;
    }
    .dialog .dialog-control {
        position: absolute;
        right: 12px;
        top: 10px;
        height: 20px;
    }
    .dialog .dialog-control .icon {
        font-size: 30px;
        text-align: center;
        line-height: 20px;
        color: #999;
        margin: 0 2px;
    }
    .dialog .dialog-control span {
        cursor: pointer;
        float: right;
    }
    .dialog .dialog-icon {
        height: 20px;
        width: 20px;
        line-height: 20px;
        font-size: 20px;
        color: #a4a9b3;
    }
    .share-dialog .content .content {
        height: 300px;
        padding: 0;
        height: auto;
    }
    .dialog-share .dialog-extra {
        color: #c0c4ce;
        line-height: 30px;
        background: #fff;
        border-radius: 0 0 4px 4px;
        text-align: center;
        font-size: 12px;
    }
    .share-dialog .content {
        height: 340px;
        background: #fff;
        font-size: 12px;
        color: #666;
    }
    .share-dialog .create-link {
        position: relative;
        padding: 30px 20px 20px;
        height: 165px;
        line-height: 24px;
    }
    .share-dialog .create-link .validity-section tr td.first-child {
        text-align: right;
    }
    .share-dialog .create-link .validity-section tr td {
        vertical-align: top;
        height: 50px;
        padding: 15px 20px 0;
        color: #8b909e;
        font-weight: 200;
    }
    .share-dialog .create-link .validity-section tr td .share-method-line {
        padding-bottom: 15px;
        position: relative;
    }

    .share-method-line span{
        font-weight: 200;
    }

    .share-dialog .create-link .validity-section tr td .share-method-line span.icon-radio-checked{
        display: inline-block;
        width: 14px;
        height: 14px;
        border-radius: 50%;
        border: 5px solid #09AAFF;
        position: relative;
        top: 2px;
    }
    .share-dialog .create-link .validity-section tr td .share-method-line label b {
        padding: 0 20px 0 10px;
        color: #424e67;
        font-weight: 400;
    }
    .share-dialog .create-link .validity-section .choose-list {
        width: 92px;
        height: 30px;
        line-height: 30px;
        margin-left: 0;
        cursor: pointer;
        border: 1px solid #e0e1e4;
        border-radius: 4px;
        padding: 0 10px;
        color: #666;
        font-size: 12px;
        outline: none;
    }
    .share-dialog .create-link .validity-section .layui-input1 {
        width: 92px;
        height: 30px;
        line-height: 30px;
        margin-left: 0;
        cursor: pointer;
        border: 1px solid #e0e1e4;
        border-radius: 4px;
        padding: 0 10px;
        color: #666;
        font-size: 12px;
        outline: none;
    }
    .share-dialog .sharefooter {
        position: absolute;
        bottom: 45px;
        padding: 0 15px;
        width: 500px;
        text-align: right;
    }

    .sharefooter .text{
        height: 32px;
        line-height: 32px;
        color: #09AAFF;
        padding: 0 30px;
        border-radius: 4px;
        display: inline-block;
        border: 1px solid #09AAFF;
        font-size: 12px;
        margin-left: 15px;
        cursor: pointer;
    }
    .sharefooter .createLink{
        color: #fff;
        background: #09AAFF;
    }
    .share-dialog .create-link .create-success{
        color: #09AAFF;
        font-size: 14px;
        position: relative;
    }
    .share-dialog .create-link .link-info {
        margin: 30px 0 16px;
        position: relative;
    }
    .share-dialog .copy-button-section {
        top: 0;
        right: 0;
        position: absolute;
        z-index: 1;
    }
    .share-dialog .copy-button-section .g-button {
        height: 32px;
        line-height: 32px;
        color: #fff;
        background: #09AAFF;
        padding: 0 10px;
        border-radius: 4px;
        display: inline-block;
        border: 1px solid #09AAFF;
        font-size: 12px;
    }
    .share-dialog .content .copy-tips {
        text-align: center;
        color: #09AAFF;
        line-height: 24px;
    }
    .share-dialog  .share-url-border {
        width: 348px;
        border: 1px solid #e9e9e9;
        border-radius: 4px;
        display: inline-block;
    }
    .share-dialog  .share-url, .share-dialog .create-link .share-password {
        height: 35px;
        line-height: 18px;
        width: 256px;
        padding: 8px;
        border: none;
        color: #666;
        border-radius: 4px;
        display: inline-block;
    }
    .share-dialog .content .border-img {
        background: #fff;
        width: 23px;
        position: absolute;
        right: 232px;
        height: 27px;
        top: 1px;
        opacity: .8;
    }
    .share-dialog .content .password {
        display: block;
        margin-top: 30px;
    }
    .share-dialog .create-link .password h4 {
        display: inline-block;
        padding: 5px 0;
        margin: 0;
        font-weight: 400;
        font-size: 12px;
    }
    .share-dialog .create-link .share-password{
        border: 1px solid #e9e9e9;
        width: 50px;
    }
    /* 上传样式	 */
    .uploadBox{
        position: fixed;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        background: rgba(0,0,0,0.6);
        z-index: 1111;
        display: none;
    }
    .uploadBoxMin{
        width: 850px;
        max-height: 600px;
        overflow: auto;
        padding: 20px;
        background: #fff;
        box-shadow: 0 0 2px 2px #eee;
        position: fixed;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
        border-radius: 4px;
    }
    .uploadBox form{
        width: auto;
    }
    .clearUplaod{
        font-size: 30px;
        line-height: 1;
        position: absolute;
        top: 20px;
        right: 20px;
        font-weight: 200;
        color: #666;
        cursor: pointer;
    }
</style>
<div th:include="include :: footer"></div>
<script src="/js/utils/js-spark-md5.js"></script>
<body class="gray-bg">
<!--<script src="/js/jquery.min.js?v=2.1.4"></script>-->
<!-- 分享 -->
<div class="module-canvas">
    <div class="dialog dialog-share   dialog-gray" id="share">
        <div class="dialog-header dialog-drag">
            <h3><span class="dialog-header-title"><em class="select-text">分享文件</em></span></h3>
            <div class="dialog-control"><span class="dialog-icon dialog-close icon icon-close"><span class="sicon quxiao">×</span></span></div>
        </div>
        <div class="dialog-body">
            <div class="share-dialog">
                <div class="content" id="_disk_id_1">
                    <div class="content-bd">
                        <div class="content-bd-left">
                            <div class="cb"></div>
                            <div class="tips-placeholder">
                                <div class="tips" style="display: none;"><em class="icon"></em><span></span><em class="icon"></em></div>
                            </div>
                            <ul class="content">
                                <li class="share-link">
                                    <div class="create-link">
                                        <table class="validity-section">
                                            <tbody>
                                            <tr>
                                                <td class="first-child"><label>分享形式</label></td>
                                                <td>
                                                    <div class="share-method-line"><span class="icon radio-icon icon-radio-checked"></span>
                                                        <label for="share-method-private"><b>有提取码</b><span>仅限拥有提取码者可查看，更加隐私安全</span></label>
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="first-child"><label>有效期</label></td>
                                                <td class="choose-panel">
                                                    <select class="choose-list" onchange="changeSelect();">
                                                        <option value="-1" selected>自定义</option>
                                                        <option value="0">永久有效</option>
                                                    </select>
                                                    <input type="text" name="sharePeriod" id="sharePeriod" value="7" class="layui-input1" maxlength="2"><span id="span1">天</span>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="sharefooter">
                                        <div class="text createLink">创建链接</div>
                                        <div class="text quxiao">取消</div>
                                    </div>
                                </li>
                                <li  class="share-link" style="display:none;">
                                    <div class="create-link">
                                        <div class="create-success">成功创建链接</div>
                                        <input id="needCopy" type="hidden" value="" />
                                        <div class="link-info">
                                            <div class="copy-button-section">
                                                <a class="g-button g-button-blue copy-button" id="copyShare">
                                                    <span class="g-button-right">
                                                        <span class="text private" onClick="copyUrl2()">复制链接</span>
                                                    </span>
                                                </a>
                                                <div style="display: none;" class="copy-tips">复制链接成功</div>
                                            </div>
                                            <div class="url">
                                                <div class="share-url-border">
                                                    <input type="text" spellingcheck="false" readonly="readonly" class="share-url"
                                                           name="shareLink" id="shareLink">
                                                    <span class="border-img"></span>
                                                    <span class="share-validity-tip">链接永久有效</span>
                                                </div>
                                            </div>
                                            <div class="password">
                                                <h4>提取码</h4>
                                                <input type="text" class="share-password" spellingcheck="false" readonly="readonly"
                                                       name="shareCode" id="shareCode">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="sharefooter">
                                        <div class="text quxiao">关闭</div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- <div class="dialog-extra g-clearfix">配合净网行动，百度网盘严厉打击色情低俗等不良信息的传播行为，如发现，将封禁账号。</div> -->
    </div>
</div>
<script>
    $(".quxiao").click(function () {
        $(".module-canvas").hide();
        $(".copy-tips").hide();
    })

    function changeSelect() {
        var val = $(".choose-list option:selected").val();
        if(val != 0) {
            $("#sharePeriod").show();
            $("#span1").show();
        }else if(val == 0) {
            $("#sharePeriod").hide();
            $("#span1").hide();
        }
    }
    $(".createLink").click(function () {
        var id = $(this).attr('setId');
        var val = $(".choose-list option:selected").val();
        if(val != 0) {
            val = $("#sharePeriod").val();
            if(val == null || val == '' ) {
                layer.msg("请输入自定义有效期");
                return false;
            }
        }
        var text = val == 0 ? $(".choose-list option:selected").text() : val+'天后失效';
        // ajax返回成功后执行以下操作
        $(".share-link").hide().eq(1).show();
        $(".share-validity-tip").html('链接'+ text);
        $.ajax({
            url : "/sys/userFile/getShareLinkAndCode",
            type : "post",
            data : {
                'fileId' : id
            },
            success : function(r) {
                $.ajax({
                    url : "/sys/userFile/createShareLink",
                    type : "post",
                    data : {
                        'fileId' : id,
                        'sharePeriod' : val,
                        'shareCode' : r.shareCode,
                        'shareLink' : r.shareLink,
                        'shareLinkMd5' : r.shareLinkMd5,
                        'uuid' : r.uuid,
                    },
                    success : function(data) {
                        if (data.code==0) {
                            $(".create-success").html("创建链接成功");
                            $("#shareLink").val(r.shareLinkMd5);
                            $("#shareCode").val(r.shareCode);
                            // 复制容器赋值
                            //$("#needCopy").val('链接:' + r.shareLinkMd5 +' 提取码:' + r.shareCode);
                            $("#needCopy").val(r.shareLinkMd5);
                        }else{
                            $(".module-canvas").hide();
                            $(".copy-tips").hide();
                            layer.msg(data.msg);
                            //$(".create-success").html("创建链接失败");
                        }
                    }
                });
            }
        });
        // 链接赋值
        // $(".share-url").html();
        // 提取码赋值
        // $(".share-password").html();
    })

    function copyUrl2() {
        var Url2 = $("#needCopy").val();
        var oInput = document.createElement('input');
        oInput.value = Url2;
        document.body.appendChild(oInput);
        oInput.select(); // 选择对象
        document.execCommand("Copy"); // 执行浏览器复制命令
        oInput.className = 'oInput';
        oInput.style.display = 'none';
        $(".copy-tips").show();
    }
</script>
<!--<script type="text/javascript" src="/js/bootstrap.js"></script>-->
<script src="/js/bootstrap-paginator.min.js"></script>
<div class="clearfix" id="content" style="height: 100%;">
    <div id="myFile">
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <div class="navbar-header"></div>
                <div class="collapse navbar-collapse">
                    <ul class="nav navbar-nav">
                        <script type="text/javascript">
                            $(function(){
                                $("#ToFileUpLaod,#ToFileUpLaod1,#folioUpLoad").change(function(){
                                    openSpinner("文件上传中。。。");
                                    $(this).parents("form.h5-uploader-form").submit();
                                });
                            });
                        </script>
                        <li class="dropdown myDropdown"><a href="javascript:void(0)"
                                                           class="fileUpLoad btn btn-default"
                                                           style="position: relative; background-color: #3b8cff; color: #FFF;overflow: hidden;"
                                                           role="button"><span class="fa fa-cloud-upload"></span>&nbsp;
                            上传
                        </a>
                            <!--                            <ul class="dropdown-menu">-->
                            <!--                                <li style="position: relative;overflow: hidden;"><a href="javascript:void(0)">上传文件-->
                            <!--                                    <form class="h5-uploader-form" action="/sys/userFile/uploadFile" method="post" enctype="multipart/form-data">-->
                            <!--                                        <input title="点击选择文件" id="ToFileUpLaod1" multiple="multiple" accept="*/*"-->
                            <!--                                               type="file" name="html5uploader">-->
                            <!--                                    </form>-->
                            <!--                                </a></li>-->
                            <!--                                <li style="position: relative;overflow: hidden;"><a-->
                            <!--                                        href="javascript:void(0)">上传文件夹-->
                            <!--                                    <form class="h5-uploader-form" action="upload/folioUpload"-->
                            <!--                                          method="post" enctype="multipart/form-data">-->
                            <!--                                        <input title="点击选择文件夹" id="folioUpLoad" multiple="multiple"-->
                            <!--                                               webkitdirectory="webkitdirectory" accept="*/*" type="file"-->
                            <!--                                               name="html5uploader">-->
                            <!--                                    </form>-->
                            <!--                                </a></li>-->
                            <!--                            </ul> -->
                            <script type="text/javascript">

                                var belong = 0;
                                var isClose = false;
                                var nameListOn = "";
                                var nameListType = "";
                                var whiteNameList = "";
                                var blackNameList = "";

                                $(function () {

                                    $(".myDropdown").click(function () {
                                        $.ajax({
                                            cache : true,
                                            type : "POST",
                                            url : "/sys/userFile/judeUpload",
                                            data : {},
                                            success : function(data) {
                                                if(data != null) {
                                                    nameListOn = data.deptDO.nameListOn;
                                                    nameListType = data.deptDO.nameListType;
                                                    whiteNameList = data.deptDO.whiteNameList;
                                                    blackNameList = data.deptDO.blackNameList;
                                                }
                                            }
                                        });
                                        $.ajax({
                                            url : "/sys/userFile/getUserDetail",
                                            type : "post",
                                            data : {},
                                            success : function(r) {
                                                if (r.code == 0) {
                                                    if(r.userDO.uploadAuthority != "" && r.userDO.uploadAuthority == "0") {
                                                        window.localStorage.clear();
                                                        $("#myFile2").click();
                                                    }else {
                                                        layer.msg("暂无上传文件权限，请联系管理员");
                                                    }
                                                }
                                            }
                                        });
                                    })
                                    $(".clearUplaod,.closeUpload").click(function () {
                                        var flag = true;
                                        $("#upload-list tr").each(function () {
                                            var res = $(this).find('td').eq(3).text();
                                            //上传成功,上传失败,上传中,暂停中,极速秒传
                                            if(res.indexOf("上传中") != -1 || res.indexOf("暂停中") != -1) {
                                                flag = false;
                                            }
                                            if(!flag) {
                                                return false;
                                            }
                                        });
                                        var fileNameList = '';
                                        $("#upload-list tr").each(function () {
                                            var res = $(this).find('td').eq(0).text();
                                            fileNameList += res + ",";
                                        });
                                        if(!flag) {
                                            isClose = true;
                                            $(".layui-layer-shade,.layui-layer").show();
                                            layer.confirm("当前存在文件正在上传，确定要关闭吗?", {
                                                btn : [ '确定', '取消' ]
                                                // 按钮
                                            }, function(index) {
                                                isPaused = 1;
                                                isClose = false;
                                                // 第一次点击上传
                                                $("#myFile2").val('');
                                                $(".uploadBox").hide();
                                                layer.close(index);
                                                window.localStorage.clear();
                                                $(".layui-layer-shade,.layui-layer").hide();
                                                currentPage = 1;
                                                pageSize = 10;
                                                filename = '';
                                                startDate = '';
                                                endDate = '';
                                                render();
                                                $.ajax({
                                                    type: 'post',
                                                    url: '/sys/userFile/cancelUploadFile',
                                                    data: {"fileNames": fileNameList},
                                                    success: function (rs) {

                                                    }
                                                });
                                            }, function(){
                                                isClose = false;
                                            });
                                        }else {
                                            isPaused = 1;
                                            $("#myFile2").val('');
                                            $(".uploadBox").hide();
                                            isClose = false;
                                            window.localStorage.clear();
                                        }
                                    })


                                    $("#myFile").find(".myDropdown").hover(function () {	//上传文件和上传文件夹
                                        $(this).find(".dropdown-menu").show();
                                    }, function () {
                                        $(this).find(".dropdown-menu").hide();
                                    }).end().find(".myCreateFile").click(function () {	//新建文件夹
                                        $(".headerTr").show().find("input[name=fileName]").focus();
                                        $(".emptyTr").hide();
                                    }).end().find(".downloadFile,.btn-group.option>.btn").click(function () {
                                        if ($(".headerTr~tr td [name=ck]:checked").length == 0) {
                                            //openModal("请选择需要下载的文件或文件夹", $("<span>确定</span>"));
                                            layer.msg("请选择文件");
                                            return false;
                                        } else {//选择了文件（tr）
                                            var $trs = $(".headerTr~tr td [name=ck]:checked").closest("tr");

                                            var typeId=[],fileId=[],oldParId=[];
                                            $.each($trs,function(i,obj){
                                                typeId.push($(obj).attr("data-type"));
                                                fileId.push($(obj).attr("data-id"));
                                                oldParId.push($(obj).attr("data-parentdir"));
                                            });
                                            if($(this).hasClass("downloadFile")){

                                                var param = "a=1";
                                                $.each(typeId,function(i,obj){
                                                    param+="&typeId="+obj+"&id="+fileId[i];
                                                    //location.href="upload/downLoad?typeId="+obj+"&id="+fileId[i];
                                                });

                                                location.href="download/load?"+param;
                                                /* $.ajax({
                                                    url:"download/test",
                                                    data:param,
                                                    beforeSend:function(){
                                                        openSpinner("努力打开下载通道中");
                                                    },success:function(data){
                                                        console.info(data);
                                                    },error:function(xhr){
                                                        alert("下载错误"+xhr.responseText);
                                                    },complete:function(){
                                                        closeSpinner();
                                                    }
                                                }); */

                                            }else if($(this).hasClass("move")){
                                                var currentFileId,fileType;
                                                $.each($trs,function(i,obj){
                                                    currentFileId+=$(obj).attr("data-id");
                                                    fileType+=$(obj).attr("data-type");
                                                    if(i<$trs.length-1){
                                                        currentFileId+=",";
                                                        fileType+=","
                                                    }
                                                });
                                                var $el = $("<span currentFileId='"+currentFileId+"' fileType='"+fileType+"' option='move'>确定</span>");
                                                $el.on('click',function(){
                                                    var $active=$(this).parents("#folioModal").find(".active-p .fa1");
                                                    moves(typeId,fileId,$active,oldParId);
                                                });
                                                openFolioModal($el,"移动到");

                                            }else if($(this).hasClass("copy")){
                                                var currentFileId,fileType;
                                                $.each($trs,function(i,obj){
                                                    currentFileId+=$(obj).attr("data-id");
                                                    fileType+=$(obj).attr("data-type");
                                                    if(i<$trs.length-1){
                                                        currentFileId+=",";
                                                        fileType+=","
                                                    }
                                                });
                                                var $el = $("<span currentFileId='"+currentFileId+"' fileType='"+fileType+"' option='copy'>确定</span>");
                                                $el.on('click',function(){
                                                    var $active=$(this).parents("#folioModal").find(".active-p .fa1");
                                                    copys(typeId,fileId,$active.attr("data-folioid"),oldParId);
                                                });
                                                openFolioModal($el,"复制到");
                                            }else if($(this).hasClass("delete")){
                                                delFolioAndFile(typeId,fileId,$($trs[0]).attr("data-parentdir"));
                                            }
                                        }
                                    });
                                });

                            </script></li>
                        <!--<li><a href="javascript:void(0)"
                               class="btn btn-default downloadFile" role="button"> <span
                                class="fa fa-download" aria-hidden="true"></span>&nbsp; 下载
                        </a></li>-->
                        <li><a href="javascript:void(0)"
                               class="btn btn-default myCreateFile" role="button"> <span
                                class="fa fa-file-o"></span>&nbsp; 新建文件夹
                        </a></li>
                        <li class="btn-group option" role="group">
                            <!--<button type="button" class="btn btn-default move">移动到</button>
                            <button type="button" class="btn btn-default copy">复制到</button>-->
                            <button type="button" class="btn btn-default" onclick="sendFile();">发送</button>
                            <!--<button type="button" class="btn btn-default" onclick="downloadFile();">下载</button>-->
                            <button type="button" class="btn btn-default" onclick="deleteFile();">删除</button>
                        </li>
                        <li>
                            <div class="form-group col-sm-3">
                                <label class="col-sm-5 control-label" style="margin-top:10px;width:30%;">文件名</label>
                                <div class="col-sm-8">
                                    <input id="filename" name="filename" type="text" class="form-control">
                                </div>
                            </div>
                            <div class="form-group col-sm-6">
                                <label class="control-label col-sm-5" style="margin-top: 10px;width:17%;">修改时间</label>
                                <div class="col-sm-8">
                                    <div class="input-daterange input-group" id="datepicker">
                                        <span class=" input-group-addon" style="border-left:1px solid #ddd;" ><i class="fa fa-calendar"></i></span>
                                        <input type="text" class="form-control" id="startDate" name="startDate" />
                                        <span class="input-group-addon">-</span>
                                        <input type="text" class="form-control" id="endDate" name="endDate" />
                                    </div>
                                </div>
                            </div>
                            <div class="form-group col-sm-2">
                                <button type="button" class="btn btn-success" onclick="reLoad()">查询</button>
                                <button type="button" class="btn btn-danger" onclick="reSet()">重置</button>
                            </div>
                        </li>
                    </ul>
                    <input type="file" style="display: none" id="myFile2" multiple />
                    <!--搜索框-->
                    <!--<form class="navbar-form navbar-right">
                        <div class="input-group">
                            <input id="searchVal" style="border-radius: 17px 0 0 17px; padding: 6px 16px;"
                                   type="text" class="form-control" placeholder="搜索您的文件">
                            <span class="input-group-btn">
									<button id="search" class="btn btn-default" type="button"
                                            style="border-radius: 0 17px 17px 0; outline: none;">
										<i class="fa fa-search" aria-hidden="true"></i>
									</button>
								</span>
                        </div>
                    </form>-->
                    <script type="text/javascript">

                        $(function(){
                            $("#search").click(function(){
                                var searchVal = $("#searchVal").val();
                                var $table = $(".myTabBox .table");
                                $.ajax({
                                    type:"GET",
                                    url:"rest/folio/listByLikeFileName/"+searchVal,
                                    beforesend:function(){
                                        openSpinner("加载中...");
                                    },
                                    success:function(data){
                                        checkShareFile(2);
                                        $table.find(".headerTr").siblings().remove();

                                        var $myFileHeader = $("#myFileHeader");
                                        $myFileHeader.find("div.last").html("已全部加载，共"+data.files.length+"个");
                                        $.each(data.files, function (i, obj) {
                                            //var fileName = obj.rname==1?obj.fileName:obj.fileName+"("+obj.rname+")";
                                            var $tr = $("<tr data-id='"+obj.id+"' data-type='"+1+"' data-parentDir='"+obj.parentDir+"'><td width='60%'><input type='checkbox' data-id='" + obj.id + "' name='ck' value='' />" +
                                                "<i class='fa "+obj.clazz+"'></i>" +
                                                "<span>" + obj.showName + "</span>" +
                                                "<div class='file-option'>" +
                                                "<i title='创建分享' class='fa fa-share-alt' aria-hidden='true'></i>" +
                                                "<i title='下载' class='fa fa-download' aria-hidden='true'></i>" +
                                                "<i title='更多' class='fa fa-ellipsis-h' aria-hidden='true'></i>" +
                                                "<div class='fileOption'><ul><li>移动到</li>" +
                                                "<li>复制到</li>" +
                                                "<li>重命名</li>" +
                                                "<li>删除</li>" +
                                                "</ul></div></div></td>" +
                                                "<td width='16%'>" + obj.size + "</td><td width='24%'>" + obj.fileUpdateTime + "</td></tr>");
                                            $table.append($tr);
                                        });
                                        closeSpinner();
                                    },error:function(e){
                                        alert("错误"+e.responseText);
                                    },complete:function(){
                                    }
                                });
                            });
                        });
                    </script>
                </div>
            </div>
        </nav>
        <!--导航路径-->
        <header id="myFileHeader">
            <div class="head bread-h cursor" parentdir="0">返回上一级</div>
            <div class="head share-h">分享文件</div>
            <div class="head recycleBin-h">回收站</div>
            <ol class="breadcrumb">
                <li class="bread-h" parentdir="0"><a href="javascript:void(0)">返回上一级</a></li>
            </ol>
            <div class="last">已全部加载，共6个</div>
        </header>
        <!--表头-->
        <table class="tableHead" border="0" cellspacing="0" cellpadding="0"
               style="width: 99%; margin-left: 2px;">
            <tr style="height: 45px;">
                <th width='30%'><input style="width: 14px; height: 14px;"
                                       type="checkbox" name="ckAll" id="ckAll" /> <span>文件名</span>
                    <button class="btn btn-default myOption recycleBin">还原</button>
                    <button class="btn btn-default myOption MyShare">取消分享</button>
                </th>
                <th width='20%'><span>类型</span></th>
                <th width='20%'><span>大小</span></th>
                <th width='10%'><span>状态</span></th>
                <th width='20%' class="orderby time" data-order="timeAsc"><span>修改时间</span></th>
            </tr>
        </table>
        <div class="myTabBox">
            <table class="table table-hover" border="0" cellspacing="0"
                   cellpadding="0">
                <tr class="headerTr">
                    <td width="30%"><input ckval="0" type='checkbox'
                                           disabled="disabled" />
                        <i class='fa fa-folder'></i>

                        <div class="FileName-div">
                            <input type="text" name="fileName" /> <span
                                class="text-center spanOption ok">√</span> <span
                                class="text-center spanOption toHide">×</span>
                        </div></td>
                    <td width="20%">--</td>
                    <td width="20%">--</td>
                    <td width="10%">--</td>
                    <td width="20%">--</td>
                </tr>
                <script type="text/javascript">

                    let filename = '';
                    let startDate = '';
                    let endDate = '';
                    let currentPage = 1;
                    let pageSize = 10;
                    let saveId = $(".breadcrumb .active").prev().attr('parentdir') ? $(".breadcrumb .active").prev().attr('parentdir') : 0;

                    $(function () {

                        var $table = $(".myTabBox .table"),
                            $ckAll = $("#ckAll"),	//全选按钮;
                            $nowtr = $(".headerTr");	//创建文件
                        $table.on('click', ".headerTr~tr", function () {
                            var $ck = $(this).find("[name=ck]");
                            if ($ck.attr("ckval") == 1) {
                                $ck.attr("ckval", 0);
                                $ck.prop("checked", false);
                            } else {
                                $ck.attr("ckval", 1);
                                $ck.prop("checked", true);
                            }

                            if ($table.find(".headerTr~tr").length == $table.find(".headerTr~tr input[name=ck]:checked").length) {
                                $ckAll.prop("checked", true);
                            } else {
                                $ckAll.prop("checked", false);
                            }
                            if($table.find(".headerTr~tr input[name=ck]:checked").length>0){
                                if($(".dt.recycleBin.bHzsaPb").length>0){
                                    $(".btn.btn-default.recycleBin").show();
                                }else if($(".dt.MyShare.bHzsaPb").length>0){
                                    $(".btn.btn-default.MyShare").show();
                                }else{
                                    $(".btn-group.option").show();
                                }
                            }else{
                                //$(".btn-group.option").hide();
                                $(".btn.btn-default.recycleBin").hide();
                                $(".btn.btn-default.MyShare").hide();
                            }
                            ///$ck.attr("ckval", 1).parents("tr").siblings("tr:not(.headerTr)").find("[name=ck]").attr("ckval", 0);
                            //$ck.prop("checked", true).parents("tr").siblings("tr:not(.headerTr)").find("[name=ck]").prop("checked", false);
                        }).on('mouseleave', ".headerTr~tr", function () {
                            $(this).find(".fileOption").hide();
                        }).on('dblclick',".headerTr~tr", function () {
                            if($(this).attr("data-type")==1 && !$(".bHzsaPb").hasClass("recycleBin") && !$(".bHzsaPb").hasClass("MyShare")){
                                //getMyFile($(this).attr("data-id"),null,"timeAsc");
                                currentPage = 1;
                                pageSize = 10;
                                saveId = $(this).attr("data-id");
                                filename = '';
                                startDate = '';
                                endDate = '';
                                render();
                            }
                        });
                        $ckAll.click(function () {
                            var isChecked = $(this).prop("checked");
                            if (isChecked == true) {
                                $table.find("input[name=ck]").attr("ckval", 1);
                                if($(".dt.recycleBin.bHzsaPb").length>0){
                                    $(".btn.btn-default.recycleBin").show();
                                }else if($(".dt.MyShare.bHzsaPb").length>0){
                                    $(".btn.btn-default.MyShare").show();
                                }else{
                                    $(".btn-group.option").show();
                                    $(".btn.btn-default.recycleBin").hide();
                                    $(".btn.btn-default.MyShare").hide();
                                }
                            } else {
                                $table.find("input[name=ck]").attr("ckval", 0);
                                closeOption();
                            }
                            $table.find(".headerTr~tr input[name=ck]").prop("checked", isChecked);
                        });

                        $nowtr.find(".toHide").click(function () {//取消创建文件夹
                            $nowtr.hide().find("input[name=fileName]").val("");
                            $(".emptyTr").show();
                        }).end().find(".ok").click(function () {
                            var $fileName = $nowtr.find("input[name=fileName]").val();
                            if ($fileName.trim().length == 0) {//确定创建文件夹
                                openModal("文本框不能为空", "<span>好的</span>");
                            } else {
                                //刷新
                                $nowtr.hide().find("input[name=fileName]").val("");//请空文本宽中的内容
                                var parentdir = $("#myFileHeader .breadcrumb li:last").attr("parentdir");
                                createFolio($fileName,parentdir,null);
                            }
                        });

                        //返回上一级
                        $(".head.bread-h").on('click',function(){
                            /*let saveId = $(".breadcrumb .active").prev().attr('parentdir') ? $(".breadcrumb .active").prev().attr('parentdir') : 0;
                            $(".head.bread-h").attr("parentdir",saveId);*/
                            //getMyFile($(this).attr("parentDir"),null,"timeAsc");
                            currentPage = 1;
                            pageSize = 10;
                            saveId = $(".breadcrumb .active").prev().attr('parentdir') ? $(".breadcrumb .active").prev().attr('parentdir') : 0;
                            filename = '';
                            startDate = '';
                            endDate = '';
                            render();
                        });
                        $("#myFileHeader .breadcrumb").on('click',"li:not(:last)",function(){
                            getMyFile($(this).attr("parentDir"),null,"timeAsc");
                        });

                        $("tr").on('click',"th.orderby",function(){
                            if($(this).hasClass("time")){
                                if($(this).attr("data-order")=="timeAsc"){
                                    $(this).attr("data-order","timeDesc")
                                }else{
                                    $(this).attr("data-order","timeAsc")
                                }
                                var target = null;
                                if(!$(".bHzsaPb").hasClass("dt")){
                                    target=$(".bHzsaPb").attr("data-type");
                                }
                                getMyFile($("#myFileHeader .breadcrumb li:last").attr("parentdir"),target,$(this).attr("data-order"));
                            }
                        });
                    });

                    function closeOption(){
                        //$(".btn-group.option").hide();
                        $(".btn.btn-default.recycleBin").hide();
                        $(".btn.btn-default.MyShare").hide();
                    }

                    function render() {
                        var FileUrl = "/sys/userFile/listFile?belong="+saveId;
                        $.ajax({
                            url:FileUrl,
                            type:"GET",
                            data: {
                                    "limit": pageSize,
                                    "offset": (currentPage-1)*pageSize,
                                    "filename": filename,
                                    "startDate": startDate,
                                    "endDate": endDate,
                                    },
                            success:function(data){
                                // 将数据渲染到页面
                                getMyFile(saveId,null,"");
                                if(data.total != 0) {
                                    $(".page").show();
                                    // 调用分页函数.参数:当前所在页, 总页数(用总条数 除以 每页显示多少条,在向上取整), ajax函数
                                    setPage(currentPage, Math.ceil(data.total/pageSize), render)
                                }else {
                                    $(".page").hide();
                                }
                            }
                        })
                    }

                    render();

                    /**
                     *
                     * @param pageCurrent 当前所在页
                     * @param pageSum 总页数
                     * @param callback 调用ajax
                     */
                    function setPage(pageCurrent, pageSum, callback) {
                        $(".pagination").bootstrapPaginator({
                            //设置版本号
                            bootstrapMajorVersion: 3,
                            // 显示第几页
                            currentPage: pageCurrent,
                            // 总页数
                            totalPages: pageSum,
                            //当单击操作按钮的时候, 执行该函数, 调用ajax渲染页面
                            onPageClicked: function (event,originalEvent,type,page) {
                                // 把当前点击的页码赋值给currentPage, 调用ajax,渲染页面
                                currentPage = page
                                callback && callback()
                            }
                        })
                    }


                    /*
						当 fileType 为空时
							得到指定目录（parentDir）下的文件夹和文件
						否者
							按文件类型进行查询
						order : 排序方式
                    */
                    function getMyFile(parentDir,fileType,order) {
                        //$(".uploadBox").hide();
                        checkShareFile(2);
                        var $myFileHeader = $("#myFileHeader"),
                            $bread=$myFileHeader.find(".breadcrumb");

                        //路径导航
                        $bread.empty().show();
                        $(".headerTr").hide();//隐藏创建文件夹的节点

                        $("#ckAll").prop("checked",false);//全选按钮
                        closeOption();//文件批量操作

                        var $table = $(".myTabBox .table");
                        $("#myFile>nav").show();
                        belong = parentDir;
                        var FileUrl = fileType == null?"/sys/userFile/listFile?belong="+parentDir:"/sys/userFile/listFile?fileType="+fileType;
                        $.ajax({
                            url:FileUrl,
                            type:"GET",
                            data: {
                                    "limit": pageSize,
                                    "offset": (currentPage-1)*pageSize,
                                    "filename": filename,
                                    "startDate": startDate,
                                    "endDate": endDate,
                                },
                            //contentType:"application/json",
                            success:function(data){
                                $table.find(".headerTr").siblings().remove();
                                /*路径导航 begin*/
                                var $liAll=$('<li parentDir="0">全部文件</li>');
                                if(data.catalog.length>0){
                                    $liAll.html('<a href="javascript:void(0)">全部文件</a>');
                                    $(".bread-h").show().attr("parentDir",data.catalog[data.catalog.length-1].parentDir).siblings(".head").hide();;
                                }else{
                                    $liAll.addClass("active");
                                    $(".head").hide();
                                }
                                $bread.append($liAll);

                                $.each(data.catalog,function(i,obj){
                                    var $li=$('<li parentDir="'+obj.id+'"><a href="javascript:void(0)">'+obj.filename+'</a></li>');
                                    if(i==data.catalog.length-1){
                                        $li.addClass("active").html(obj.filename).siblings("li").removeClass("active");
                                    }
                                    $bread.append($li);
                                });
                                /*路径导航 end*/

                                $myFileHeader.find("div.last").html("已全部加载，共"+data.rows.length+"个");
                                if(data.rows.length==0){
                                    $table.append('<tr class="emptyTr text-center"><td colspan="3" style="height:60px;line-height:60px;">'+
                                        '您还没上传过文件哦，点击上传选择文件按钮～'+
                                        '</td><tr>');
                                }
                                $.each(data.rows, function (i, obj) {
                                    var classStyle = "";
                                    if(obj.isFolder == 1) {
                                        classStyle = "fa fa-folder";
                                    }
                                    var filetypeStr = "--"
                                    if(obj.filetype != null) {
                                        filetypeStr = obj.filetype;
                                    }
                                    var statusName = "--";
                                    if(obj.status != null) {
                                        //-1：类型检查失败，-2：存在病毒，-3：加密失败，0：上传成功
                                        if(obj.status == -1) {
                                            statusName = "类型检查失败";
                                        }else if(obj.status == -2) {
                                            statusName = "病毒文件,已清除";
                                        }else if(obj.status == -3) {
                                            statusName = "加密失败";
                                        }else {
                                            statusName = "正常";
                                        }
                                    }
                                    var documentType = '';
                                    if(filetypeStr == 'jpg' || filetypeStr == 'jpeg' || filetypeStr == 'JPEG' || filetypeStr == 'png' ||  filetypeStr == 'PNG' || filetypeStr == 'GIF' ||  filetypeStr == 'gif' || filetypeStr == 'TIFF' || filetypeStr == 'tif' || filetypeStr == 'bmp'){
                                        documentType = '<img src="../../img/documenttype1.png" />'
                                    }else if(filetypeStr == 'dwg'){
                                        documentType = '<img src="../../img/documenttype2.png" />'
                                    }else if(filetypeStr == 'html'){
                                        documentType = '<img src="../../img/documenttype3.png" />'
                                    }else if(filetypeStr == 'css'){
                                        documentType = '<img src="../../img/documenttype4.png" />'
                                    }else if(filetypeStr == 'js'){
                                        documentType = '<img src="../../img/documenttype5.png" />'
                                    }else if(filetypeStr == 'rtf'){
                                        documentType = '<img src="../../img/documenttype6.png" />'
                                    }else if(filetypeStr == 'psd'){
                                        documentType = '<img src="../../img/documenttype7.png" />'
                                    }else if(filetypeStr == 'eml'){
                                        documentType = '<img src="../../img/documenttype8.png" />'
                                    }else if(filetypeStr == 'doc' || filetypeStr == 'docx'){
                                        documentType = '<img src="../../img/documenttype9.png" />'
                                    }else if(filetypeStr == 'vsd'){
                                        documentType = '<img src="../../img/documenttype10.png" />'
                                    }else if(filetypeStr == 'mdb'){
                                        documentType = '<img src="../../img/documenttype11.png" />'
                                    }else if(filetypeStr == 'ps'){
                                        documentType = '<img src="../../img/documenttype12.png" />'
                                    }else if(filetypeStr == 'pdf'){
                                        documentType = '<img src="../../img/documenttype13.png" />'
                                    }else if(filetypeStr == 'flv' || filetypeStr == 'mp4' || filetypeStr == 'mpg' || filetypeStr == 'avi'){
                                        documentType = '<img src="../../img/documenttype14.png" />'
                                    }else if(filetypeStr == 'mp3' || filetypeStr == 'wav' || filetypeStr == 'mid'){
                                        documentType = '<img src="../../img/documenttype15.png" />'
                                    }else if(filetypeStr == 'wmv'){
                                        documentType = '<img src="../../img/documenttype16.png" />'
                                    }else if(filetypeStr == 'zip' || filetypeStr == 'rar'){
                                        documentType = '<img src="../../img/documenttype17.png" />'
                                    }else if(filetypeStr == 'ini'){
                                        documentType = '<img src="../../img/documenttype18.png" />'
                                    }else if(filetypeStr == 'jar'){
                                        documentType = '<img src="../../img/documenttype19.png" />'
                                    }else if(filetypeStr == 'exe'){
                                        documentType = '<img src="../../img/documenttype20.png" />'
                                    }else if(filetypeStr == 'jsp'){
                                        documentType = '<img src="../../img/documenttype21.png" />'
                                    }else if(filetypeStr == 'mf'){
                                        documentType = '<img src="../../img/documenttype22.png" />'
                                    }else if(filetypeStr == 'xml'){
                                        documentType = '<img src="../../img/documenttype23.png" />'
                                    }else if(filetypeStr == 'sql'){
                                        documentType = '<img src="../../img/documenttype24.png" />'
                                    }else if(filetypeStr == 'java'){
                                        documentType = '<img src="../../img/documenttype25.png" />'
                                    }else if(filetypeStr == 'bat'){
                                        documentType = '<img src="../../img/documenttype26.png" />'
                                    }else if(filetypeStr == 'gz'){
                                        documentType = '<img src="../../img/documenttype27.png" />'
                                    }else if(filetypeStr == 'properties'){
                                        documentType = '<img src="../../img/documenttype28.png" />'
                                    }else if(filetypeStr == 'class'){
                                        documentType = '<img src="../../img/documenttype29.png" />'
                                    }else if(filetypeStr == 'chm'){
                                        documentType = '<img src="../../img/documenttype30.png" />'
                                    }else if(filetypeStr == 'mxp'){
                                        documentType = '<img src="../../img/documenttype31.png" />'
                                    }else if(filetypeStr == 'docx'){
                                        documentType = '<img src="../../img/documenttype32.png" />'
                                    }else if(filetypeStr == 'wps'){
                                        documentType = '<img src="../../img/documenttype33.png" />'
                                    }else if(filetypeStr == 'torrent'){
                                        documentType = '<img src="../../img/documenttype34.png" />'
                                    }else if(filetypeStr == 'wpd'){
                                        documentType = '<img src="../../img/documenttype35.png" />'
                                    }else if(filetypeStr == 'dbx'){
                                        documentType = '<img src="../../img/documenttype36.png" />'
                                    }else if(filetypeStr == 'pst'){
                                        documentType = '<img src="../../img/documenttype37.png" />'
                                    }else if(filetypeStr == 'qdf'){
                                        documentType = '<img src="../../img/documenttype38.png" />'
                                    }else if(filetypeStr == 'wmv'){
                                        documentType = '<img src="../../img/documenttype39.png" />'
                                    }else if(filetypeStr == 'pwl'){
                                        documentType = '<img src="../../img/documenttype40.png" />'
                                    }else if(filetypeStr == 'ram'){
                                        documentType = '<img src="../../img/documenttype41.png" />'
                                    }else if(filetypeStr == 'amr'){
                                        documentType = '<img src="../../img/documenttype42.png" />'
                                    }else {
                                        if(obj.isFolder != 1) {
                                            documentType = '<img src="../../img/documenttype43.png" />'
                                        }
                                    }
                                    //var fileName = obj.rname==1?obj.fileName:obj.fileName+"("+obj.rname+")";
                                    var $tr = $("<tr data-id='"+obj.id+"' data-type='"+obj.isFolder+"' data-parentDir='"+obj.belong+"' data-title='" + obj.isFolder + "'>" +
                                        "<td width='30%' title='"+obj.filename+"'><input type='checkbox' data-id='" + obj.isFolder + "' name='ck' value='' />" +
                                        "<i class='"+classStyle+"'></i>" +
                                        "<span>" + obj.filename.substring(0,20) + "</span>" +
                                        "<div class='file-option'>" +
                                        "<i title='创建分享' class='fa fa-share-alt' aria-hidden='true'></i>" +
                                        "<i title='下载' class='fa fa-download' aria-hidden='true'></i>" +
                                        /*"<i title='更多' class='fa fa-ellipsis-h' aria-hidden='true'></i>" +*/
                                        "<div class='fileOption'><ul>" +
                                        /*"<li>重命名</li>" +
                                        "<li>删除</li>" +*/
                                        "</ul></div></div></td>" +
                                        "<td width='20%'>" + documentType + filetypeStr + "</td>" +
                                        "<td width='20%'>" + obj.filesizeStr + "</td>" +
                                        "<td width='10%'>" + statusName + "</td>" +
                                        "<td width='20%'>" + obj.addtime + "</td></tr>");
                                    $tr.find(".fileOption>ul").on('click', 'li', function () {
                                        if ($(this).html() == "重命名") {
                                            $tr.find("td:eq(0) .fa").siblings("span,div").hide();
                                            var createFile = $('<div class="FileName-div"><input type="text" name="fileName" value="' + obj.showName + '" /><span class="text-center spanOption ok">√</span><span class="text-center spanOption toHide">×</span></div>');
                                            var input = createFile.find("input");
                                            createFile.find(".toHide").on('click', function () {
                                                createFile.remove();
                                                $tr.find("td:eq(0) .fa").siblings("span,div").show();
                                                return false;
                                            }).end().find(".ok").click(function () {//确定修改
                                                createFile.remove();
                                                $tr.find("td:eq(0) .fa").siblings("span,div").show();
                                                var $th = $(this);
                                                $.ajax({
                                                    type:"put",
                                                    url:"rest/folio/"+obj.type,
                                                    data:"parentDir="+obj.parentDir+"&fileName="+$th.siblings("[name=fileName]").val().trim()+"&id="+obj.id,
                                                    //contentType:"application/json",
                                                    success:function(data){
                                                        checkMsg(data.msg,data.status);
                                                        if(data.status==200)
                                                            getMyFile(obj.parentDir,null,"timeAsc");
                                                    },
                                                    error:function(xhr){
                                                        alert("修改错误\n"+xhr.responseText);
                                                    }
                                                });
                                                return false;
                                            });
                                            input.on('click', function () {return false;}).on('dblclick',function(){return false;});
                                            $tr.find("td:eq(0)").append(createFile);
                                        }else if($(this).html() == "删除"){
                                            var typeId=[obj.type],fileId=[obj.id];
                                            delFolioAndFile(typeId,fileId,obj.parentDir);
                                        }else if($(this).html() == "复制到"){
                                            var $el = $("<span currentFileId='"+obj.id+"' fileType='"+obj.type+"' option='copy'>确定</span>");
                                            $el.on('click',function(){
                                                var $active=$(this).parents("#folioModal").find(".active-p .fa1");

                                                var typeId=[obj.type],
                                                    fileId=[obj.id],
                                                    oldParId=[obj.parentDir];
                                                copys(typeId,fileId,$active.attr("data-folioid"),oldParId);
                                            });
                                            openFolioModal($el,"复制到");
                                        }else if($(this).html() == "移动到"){
                                            var $el = $("<span currentFileId='"+obj.id+"' fileType='"+obj.type+"' option='move'>确定</span>");
                                            $el.on('click',function(){
                                                var $active=$(this).parents("#folioModal").find(".active-p .fa1");

                                                var typeId=[obj.type],
                                                    fileId=[obj.id],
                                                    oldParId=[obj.parentDir];
                                                moves(typeId,fileId,$active,oldParId);
                                            });
                                            openFolioModal($el,"移动到");
                                        }
                                        return false;
                                    }).end().find("td:eq(0)").on('click', '.fa', function () {
                                        var $th = $(this);
                                        if ($th.hasClass("fa-share-alt")) {//分享
                                            var filename = obj.filename;
                                            var id = obj.id;
                                            $(".select-text").html('分享文件(夹):'+filename)
                                            $(".module-canvas").show();
                                            $(".createLink").attr('setId',id);
                                            $(".share-link").hide().eq(0).show();
                                        } else if ($th.hasClass("fa-download")) {//下载
                                            /*if(obj.type==2){
                                                location.href="upload/downLoad?typeId="+obj.type+"&id="+obj.id;
                                            }else{
                                                createMeg("占时还不提供下载文件夹哦");
                                            }*/
                                            //判断文件是否可以下载
                                            $.ajax({
                                                url : "/sys/userFile/getUserDetail",
                                                type : "post",
                                                data : {},
                                                success : function(r) {
                                                    if (r.code == 0) {
                                                        if(r.userDO.downloadAuthority != "" && r.userDO.downloadAuthority == "0") {
                                                            $.ajax({
                                                                url : "/sys/userFile/judeDownloadFile",
                                                                type : "post",
                                                                data : {
                                                                    'fileId' : obj.id,
                                                                    'uuid' : obj.uuid,
                                                                    'flag' : "1"
                                                                },
                                                                success : function(r) {
                                                                    if (r.code==0) {
                                                                        window.location.href = "/sys/userFile/downloadFile?uuid=" + obj.uuid + "&fileId=" + obj.id;
                                                                    }else{
                                                                        layer.msg(r.msg);
                                                                    }
                                                                }
                                                            });
                                                        }else {
                                                            layer.msg("暂无下载文件权限，请联系管理员");
                                                        }
                                                    }
                                                }
                                            });
                                        } else if ($th.hasClass("fa-ellipsis-h")) {//更多
                                            $th.siblings(".fileOption").show();
                                        }
                                        return false;
                                    }).end().find("td:eq(0)").on('dblclick', '.fa', function () {
                                        return false;
                                    }).end().find(".fileOption>ul").on('dblclick', 'li', function () {
                                        return false;
                                    });
                                    $table.append($tr);
                                });
                                closeSpinner();
                            },error:function(e){
                                alert("错误"+e.responseText);
                            },complete:function(){
                            }
                        });//ajax
                    }

                    function getMyFileFor(parentDir,fileType,order) {
                        //$(".uploadBox").hide();
                        checkShareFile(2);
                        var $myFileHeader = $("#myFileHeader"),
                            $bread=$myFileHeader.find(".breadcrumb");

                        //路径导航
                        $bread.empty().show();
                        $(".headerTr").hide();//隐藏创建文件夹的节点

                        $("#ckAll").prop("checked",false);//全选按钮
                        closeOption();//文件批量操作

                        var $table = $(".myTabBox .table");
                        $table.find(".headerTr").siblings().remove();

                        $("#myFile>nav").show();
                        belong = parentDir;
                        var FileUrl = fileType == null?"/sys/userFile/listFile?belong="+parentDir:"/sys/userFile/listFile?fileType="+fileType;
                        $.ajax({
                            url:FileUrl,
                            type:"GET",
                            //contentType:"application/json",
                            beforeSend:function(){
                                openSpinner("拼命加载中！！！");
                            },success:function(data){
                                /*路径导航 begin*/
                                var $liAll=$('<li parentDir="0">全部文件</li>');
                                if(data.catalog.length>0){
                                    $liAll.html('<a href="javascript:void(0)">全部文件</a>');
                                    $(".bread-h").show().attr("parentDir",data.catalog[data.catalog.length-1].parentDir).siblings(".head").hide();;
                                }else{
                                    $liAll.addClass("active");
                                    $(".head").hide();
                                }
                                $bread.append($liAll);

                                $.each(data.catalog,function(i,obj){
                                    var $li=$('<li parentDir="'+obj.id+'"><a href="javascript:void(0)">'+obj.filename+'</a></li>');
                                    if(i==data.catalog.length-1){
                                        $li.addClass("active").html(obj.filename).siblings("li").removeClass("active");
                                    }
                                    $bread.append($li);
                                });
                                /*路径导航 end*/

                                $myFileHeader.find("div.last").html("已全部加载，共"+data.rows.length+"个");
                                if(data.rows.length==0){
                                    $table.append('<tr class="emptyTr text-center"><td colspan="3" style="height:60px;line-height:60px;">'+
                                        '您还没上传过文件哦，点击上传选择文件按钮～'+
                                        '</td><tr>');
                                }
                                $.each(data.rows, function (i, obj) {
                                    var classStyle = "";
                                    if(obj.isFolder == 1) {
                                        classStyle = "fa fa-folder";
                                    }
                                    var filetypeStr = "--"
                                    if(obj.filetype != null) {
                                        filetypeStr = obj.filetype;
                                    }
                                    var statusName = "--";
                                    if(obj.status != null) {
                                        //-1：类型检查失败，-2：存在病毒，-3：加密失败，0：上传成功
                                        if(obj.status == -1) {
                                            statusName = "类型检查失败";
                                        }else if(obj.status == -2) {
                                            statusName = "存在病毒";
                                        }else if(obj.status == -3) {
                                            statusName = "加密失败";
                                        }else {
                                            statusName = "正常";
                                        }
                                    }
                                    //var fileName = obj.rname==1?obj.fileName:obj.fileName+"("+obj.rname+")";
                                    var $tr = $("<tr data-id='"+obj.id+"' data-type='"+obj.isFolder+"' data-parentDir='"+obj.belong+"' data-title='" + obj.isFolder + "'>" +
                                        "<td width='30%'><input type='checkbox' data-id='" + obj.isFolder + "' name='ck' value='' />" +
                                        "<i class='"+classStyle+"'></i>" +
                                        "<span>" + obj.filename + "</span>" +
                                        "<div class='file-option'>" +
                                        "<i title='创建分享' class='fa fa-share-alt' aria-hidden='true'></i>" +
                                        "<i title='下载' class='fa fa-download' aria-hidden='true'></i>" +
                                        /*"<i title='更多' class='fa fa-ellipsis-h' aria-hidden='true'></i>" +*/
                                        "<div class='fileOption'><ul>" +
                                        /*"<li>重命名</li>" +
                                        "<li>删除</li>" +*/
                                        "</ul></div></div></td>" +
                                        "<td width='20%'>" + filetypeStr + "</td>" +
                                        "<td width='20%'>" + obj.filesizeStr + "</td>" +
                                        "<td width='10%'>" + statusName + "</td>" +
                                        "<td width='20%'>" + obj.addtime + "</td></tr>");
                                    $tr.find(".fileOption>ul").on('click', 'li', function () {
                                        if ($(this).html() == "重命名") {
                                            $tr.find("td:eq(0) .fa").siblings("span,div").hide();
                                            var createFile = $('<div class="FileName-div"><input type="text" name="fileName" value="' + obj.showName + '" /><span class="text-center spanOption ok">√</span><span class="text-center spanOption toHide">×</span></div>');
                                            var input = createFile.find("input");
                                            createFile.find(".toHide").on('click', function () {
                                                createFile.remove();
                                                $tr.find("td:eq(0) .fa").siblings("span,div").show();
                                                return false;
                                            }).end().find(".ok").click(function () {//确定修改
                                                createFile.remove();
                                                $tr.find("td:eq(0) .fa").siblings("span,div").show();
                                                var $th = $(this);
                                                $.ajax({
                                                    type:"put",
                                                    url:"rest/folio/"+obj.type,
                                                    data:"parentDir="+obj.parentDir+"&fileName="+$th.siblings("[name=fileName]").val().trim()+"&id="+obj.id,
                                                    //contentType:"application/json",
                                                    success:function(data){
                                                        checkMsg(data.msg,data.status);
                                                        if(data.status==200)
                                                            getMyFile(obj.parentDir,null,"timeAsc");
                                                    },
                                                    error:function(xhr){
                                                        alert("修改错误\n"+xhr.responseText);
                                                    }
                                                });
                                                return false;
                                            });
                                            input.on('click', function () {return false;}).on('dblclick',function(){return false;});
                                            $tr.find("td:eq(0)").append(createFile);
                                        }else if($(this).html() == "删除"){
                                            var typeId=[obj.type],fileId=[obj.id];
                                            delFolioAndFile(typeId,fileId,obj.parentDir);
                                        }else if($(this).html() == "复制到"){
                                            var $el = $("<span currentFileId='"+obj.id+"' fileType='"+obj.type+"' option='copy'>确定</span>");
                                            $el.on('click',function(){
                                                var $active=$(this).parents("#folioModal").find(".active-p .fa1");

                                                var typeId=[obj.type],
                                                    fileId=[obj.id],
                                                    oldParId=[obj.parentDir];
                                                copys(typeId,fileId,$active.attr("data-folioid"),oldParId);
                                            });
                                            openFolioModal($el,"复制到");
                                        }else if($(this).html() == "移动到"){
                                            var $el = $("<span currentFileId='"+obj.id+"' fileType='"+obj.type+"' option='move'>确定</span>");
                                            $el.on('click',function(){
                                                var $active=$(this).parents("#folioModal").find(".active-p .fa1");

                                                var typeId=[obj.type],
                                                    fileId=[obj.id],
                                                    oldParId=[obj.parentDir];
                                                moves(typeId,fileId,$active,oldParId);
                                            });
                                            openFolioModal($el,"移动到");
                                        }
                                        return false;
                                    }).end().find("td:eq(0)").on('click', '.fa', function () {
                                        var $th = $(this);
                                        if ($th.hasClass("fa-share-alt")) {//分享
                                            var filename = obj.filename;
                                            var id = obj.id;
                                            $(".select-text").html('分享文件(夹):'+filename)
                                            $(".module-canvas").show();
                                            $(".createLink").attr('setId',id);
                                            $(".share-link").hide().eq(0).show();
                                        } else if ($th.hasClass("fa-download")) {//下载
                                            /*if(obj.type==2){
                                                location.href="upload/downLoad?typeId="+obj.type+"&id="+obj.id;
                                            }else{
                                                createMeg("占时还不提供下载文件夹哦");
                                            }*/
                                            window.location.href = "/sys/userFile/downloadFile?uuid=" + obj.id;
                                        } else if ($th.hasClass("fa-ellipsis-h")) {//更多
                                            $th.siblings(".fileOption").show();
                                        }
                                        return false;
                                    }).end().find("td:eq(0)").on('dblclick', '.fa', function () {
                                        return false;
                                    }).end().find(".fileOption>ul").on('dblclick', 'li', function () {
                                        return false;
                                    });
                                    $table.append($tr);
                                });
                                closeSpinner();
                            },error:function(e){
                                alert("错误"+e.responseText);
                            },complete:function(){
                            }
                        });//ajax
                    }

                    //检查文件原来的父文件夹下--为了 copys函数和moves函数
                    function checkInfo(oldParId,parentDir){
                        for(var i =0 ; i< oldParId.length;i++){
                            if(oldParId[i]==parentDir){
                                return false;
                            }
                        }
                        return true;
                    }
                    //批量复制
                    function copys(typeId,id,parentDir,oldParId){
                        /* if(!checkInfo(oldParId,parentDir)){
                            createMeg("不能将文件复制到自身或其子目录下");
                            return false;
                        }else{*/
                        var param = "parentDir="+parentDir;
                        $.each(typeId,function(i,obj){
                            param+="&typeId="+obj+"&id="+id[i];
                        });
                        openSpinner("文件拼命复制中。。。");
                        $.ajax({
                            type:"POST",
                            url:"rest/folio/copys",
                            data:param,
                            beforeSend:function(){
                                openSpinner("文件拼命复制中。。。");
                            },success:function(data){
                                checkMsg(data.msg,data.status);
                                if(data.status==200){
                                    getMyFile($("#myFileHeader .breadcrumb li:last").attr("parentdir"),null,"timeAsc");
                                }
                            },error:function(xhr){
                                alert("文件复制错误\n"+xhr.responseText);
                            },complete:function(){
                                closeSpinner();
                            }
                        });
                        //}
                    }
                    //批量移动
                    function moves(typeId,id,$active,oldParId){
                        var parentDir=$active.attr("data-folioid")
                        if(!checkInfo(oldParId,parentDir)){
                            createMeg("不能将文件移动到自身或其子目录下");
                            return false;
                        }else if($active.length>0){
                            var param = "parentDir="+parentDir;
                            $.each(typeId,function(i,obj){
                                param+="&typeId="+obj+"&id="+id[i];
                            });
                            $.ajax({
                                type:"PUT",
                                url:"rest/folio/moves",
                                data:param,
                                beforeSend:function(){
                                    openSpinner("文件拼命移动中。。。");
                                },success:function(data){
                                    checkMsg(data.msg,data.status);
                                    if(data.status==200){
                                        getMyFile($("#myFileHeader .breadcrumb li:last").attr("parentdir"),null,"timeAsc");
                                    }
                                },error:function(xhr){
                                    alert("文件移动错误\n"+xhr.responseText);
                                },complete:function(){
                                    closeSpinner();
                                }
                            });
                        }else{
                            createMeg("请选择文件夹");
                            return false;
                        }
                    }
                    //批量删除
                    function delFolioAndFile(typeId,fileId,parentDir){
                        var param="a=1";
                        $.each(typeId,function(i,obj){
                            param+="&id="+fileId[i]+"&typeId="+obj;
                        });
                        $.ajax({
                            type:"PUT",
                            url:"rest/folio",
                            data:param,
                            success:function(data){
                                checkMsg(data.msg,data.status);
                                if(data.status==200)
                                    getMyFile(parentDir,null,"timeAsc");
                            },
                            error:function(xhr){
                                alert("删除错误\n"+xhr.responseText);
                            }
                        });
                    }
                </script>
            </table>
            <div class="page" style="margin: 30px 0;text-align: center">
                <ul class="pagination"></ul>
            </div>
        </div>
    </div>
</div>


<div id="myModal" class="modal fade" tabindex="10" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">温馨提示</h4>
            </div>
            <div class="modal-body">
                <p style="margin: 14px 0;"></p>
            </div>
            <div class="modal-footer">
                <button type="button"
                        style="padding-left: 30px; padding-right: 30px;"
                        class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button"
                        style="padding-left: 30px; padding-right: 30px;"
                        class="btn btn-primary" data-dismiss="modal">确定</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("#myModal").on("show.bs.modal", function (e) {

        }).on("shown.bs.modal", function (e) {

        }).on("hide.bs.modal", function (e) {

        }).on("hidden.bs.modal", function (e) {
            //内容清空
            $(this).removeData("bs.modal");
        }).on("loaded.bs.modal", function (e) {

        });

        $("#folioModal").on("show.bs.modal", function (e) {
            getFolio(0,$("#folioModalBody .folioAll"));
            $("div.p").removeClass("active-p").css("border-color","rgba(0,0,0,0)");
            $(".folioAll.childrenDiv").find("div,p:eq(0)").addClass("active-p").css("border-color","rgb(154, 205, 253)");
        }).on("shown.bs.modal", function (e) {

        }).on("hide.bs.modal", function (e) {

        }).on("hidden.bs.modal", function (e) {
            //内容清空
            $(this).removeData("bs.modal");
        }).on("loaded.bs.modal", function (e) {

        });

    });
    function openModal(content, $el) {
        var $myModal = $("#myModal");
        $myModal.modal("show").find(".modal-body>p").html(content).end()
            .find(".modal-footer button:eq(1)").html("").addClass("getBtn").css("padding", "0").append($el);

    }
</script>

<style>
    .myTabBox .table tr td:first-of-type>.fa-th-large{cursor:pointer;color: #43a0ff;background-color: #ffc644;
        padding: 2px 4px 0 4px;border-radius: 4px;}
</style>
<script type="text/javascript">
    $(function(){
        $(".btn.btn-default.myOption.recycleBin").click(function(){
            var $trs = $(".headerTr~tr td [name=ck]:checked").closest("tr");
            if($trs.length==0){
                openModal("请选择需要还原的文件或文件夹", $("<span>确定</span>"));
            }
            var typeId=[],fileId=[];
            $.each($trs,function(i,obj){
                typeId.push($(obj).attr("data-type"));
                fileId.push($(obj).attr("data-id"));
            });
            restoreFolioOrFile(typeId,fileId);
        });
    });

    function myShare(){
        checkShareFile(1);
        var $myFileHeader = $("#myFileHeader"),
            $bread=$myFileHeader.find(".breadcrumb");
        $table = $(".myTabBox .table");
        $bread.find("*").hide();
        $myFileHeader.find(".share-h").show().siblings("head").hide();
        $table.find(".headerTr").siblings().remove();
        $.ajax({
            type:"GET",
            url:"rest/fileShare/fileShareDetail",
            beforeSend:function(){
                openSpinner("拼命加载中！！")
            },success:function(data){
                $myFileHeader.find("div.last").html("已全部加载，共"+data.length+"个");
                if(data.length==0){
                    $table.append('<tr class="emptyTr text-center"><td colspan="4" style="height:60px;line-height:60px;">'+
                        '您没有有效的分享文件噢～</td><tr>');
                }
                $.each(data, function (i, obj) {
                    var showName,clazz;
                    if(obj.folioInfoVos.length>1){
                        showName=obj.folioInfoVos[0].showName+"等多个文件";
                        clazz="fa-th-large";
                    }else{
                        showName=obj.folioInfoVos[0].showName;
                        clazz=obj.folioInfoVos[0].clazz;
                    }
                    var $tr = $("<tr data-id='"+obj.folioInfoVos[0].id+"' data-type='"+1+"' data-title='" + obj.isFolder + "'><td width='48%'><input type='checkbox' data-id='" + obj.id + "' name='ck' value='' />" +
                        "<i class='fa "+clazz+"'></i>" +
                        "<span>" + showName + "</span>" +
                        "<div class='file-option'>" +
                        "<i title='取消分享' class='fa fa-undo' aria-hidden='true'></i>" +
                        "</div></td>" +
                        "<td width='16%'>" + obj.downloadNum + "</td><td width='20%'>" + obj.sharingTime + "</td>"+
                        "<td width='20%'>" + obj.outTime + "</td></tr>");
                    if(obj.folioInfoVos.length>1){
                        $tr.on("dblclick",function(){
                            showShareFileInfo(obj.id);
                        });
                    }
                    $tr.find("td:eq(0)").on('click', '.fa', function () {
                        var id=[obj.id];
                        var $el=$("<span>确定</span>");
                        $el.on('click',function(){
                            $.ajax({
                                type:"DELETE",
                                url:"rest/fileShare/"+obj.id,
                                beforeSend:function(){
                                    openSpinner("删除分享链接中。。");
                                },complete:function(){
                                    closeSpinner();
                                },error:function(xhr){
                                    alert("删除分享错误\n"+xhr.responseText);
                                },success:function(data){
                                    checkMsg(data.msg,data.status);
                                    if(data.status==200)
                                        myShare();
                                }
                            });
                        });
                        openModal("取消分享后，该条分享记录将被删除，好友将无法再访问此分享链接。你确认要取消分享吗？！请谨慎此操作", $el);
                        return false;
                    }).end().find("td:eq(0)").on('dblclick', '.fa', function () {
                        return false;
                    }).end().find(".fileOption>ul").on('dblclick', 'li', function () {
                        return false;
                    });
                    $table.append($tr);
                });
            },complete:function(){
                closeSpinner();
            }
        });
    }

    function checkShareFile(num){
        if(num==1){
            $("#myFile>table:eq(0)").find("th:eq(0)").attr("width","48%")
                .end().find("th:eq(1)").html("<span>下载次数</span>").attr("width","16%")
                .end().find("th:eq(2)").html("<span>分享时间</span>").attr("width","20%").removeClass("orderby")
                .after("<th width='20%' class='lastTh'><span>失效时间</span></th>");
        }else{
            $("#myFile>table:eq(0) .lastTh").remove();
            $("#myFile>table:eq(0)").find("th:eq(0)").attr("width","30%")
                .end().find("th:eq(1)").html("<span>类型</span>").attr("width","20%")
                .end().find("th:eq(2)").html("<span>大小</span>").attr("width","20%")
                .end().find("th:eq(3)").html("<span>状态</span>").attr("width","10%")
                .end().find("th:eq(4)").html("<span>修改时间</span>").attr("width","20%").addClass("orderby");
        }

    }

    function recycleBin(){
        checkShareFile(2);
        var $myFileHeader = $("#myFileHeader"),
            $bread=$myFileHeader.find(".breadcrumb");
        $table = $(".myTabBox .table");
        $myFileHeader.find(".head.bread-h.cursor").hide();
        $bread.find("*").hide();
        $myFileHeader.find(".recycleBin-h").show().siblings("head").hide();
        $table.find(".headerTr").siblings().remove();

        $("#myFile>nav").css("display","none");
        $.ajax({
            type:"GET",
            url:"rest/folio/-1",
            data:"isNotDel=2",
            beforeSend:function(){
                openSpinner("拼命加载中！！")
            },success:function(data){
                $myFileHeader.find("div.last").html("已全部加载，共"+data.rows.length+"个");
                if(data.rows.length==0){
                    $table.append('<tr class="emptyTr text-center"><td colspan="3" style="height:60px;line-height:60px;">'+
                        '您的回收站为空噢～</td><tr>');
                }
                $.each(data.rows, function (i, obj) {
                    var $tr = $("<tr data-id='"+obj.id+"' data-type='"+1+"'><td width='60%'><input type='checkbox' data-id='" + obj.id + "' name='ck' value='' />" +
                        "<i class='fa "+obj.clazz+"'></i>" +
                        "<span>" + obj.showName + "</span>" +
                        "<div class='file-option'>" +
                        "<i title='还原' class='fa fa-undo' aria-hidden='true'></i>" +
                        "<i title='彻底删除' class='fa fa-trash-o' aria-hidden='true'></i>" +
                        "</div></td>" +
                        "<td width='16%'>" + obj.size + "</td><td width='24%'>" + obj.fileUpdateTime + "</td></tr>");
                    $tr.find("td:eq(0)").on('click', '.fa', function () {
                        var $th = $(this);
                        if ($th.hasClass("fa-undo")) {//还原
                            var typeId=[obj.type],id=[obj.id];
                            restoreFolioOrFile(typeId,id);
                        } else if ($th.hasClass("fa-trash-o")) {//彻底删除
                            var $el=$("<span>确定删除</span>");
                            $el.on('click',function(){
                                $.ajax({
                                    type:"DELETE",
                                    url:"rest/folio/"+obj.id+"/"+obj.type,
                                    beforeSend:function(){
                                        openSpinner("正在抛弃文件中。。");
                                    },complete:function(){
                                        closeSpinner();
                                    },error:function(xhr){
                                        alert("彻底删除错误\n"+xhr.responseText);
                                    },success:function(data){
                                        checkMsg(data.msg,data.status);
                                        if(data.status==200)
                                            recycleBin();
                                    }
                                });
                            });
                            openModal("彻底删除的文件或文件将无法复原哦！请谨慎此操作", $el);
                        }
                        return false;
                    }).end().find("td:eq(0)").on('dblclick', '.fa', function () {
                        return false;
                    }).end().find(".fileOption>ul").on('dblclick', 'li', function () {
                        return false;
                    });
                    $table.append($tr);
                });
            },complete:function(){
                closeSpinner();
            }
        });
    }

    //还原文件或者文件夹
    function restoreFolioOrFile(typeId,id){

        var param="a=1";
        $.each(typeId,function(i,obj){
            param += "&typeId="+obj+"&id="+id[i];
        });
        $.ajax({
            type:"PUT",
            url:"rest/folio/restore",
            data:param,
            beforeSend:function(){
                openSpinner("文件飞速还原中，请稍等。。。");
            },success:function(data){
                checkMsg(data.msg,data.status);
                if(data.status==200)
                    recycleBin();
            },error:function(xhr){
                alert("还原错误\n"+xhr.responseText);
            },complete:function(){
                closeSpinner();
            }
        });
    }
</script>


<div class="modal-footer">
    <script>
        $(function(){
            var $div =$("#folioModalBody>div:eq(0)");
            $div.on('click',"div.p:not(.now)",function(){
                $("div.p").removeClass("active-p").css("border-color","rgba(0,0,0,0)");
                $(this).addClass("active-p").css("border-color","#9acdfd");

                var $fa1=$(this).find(".fa1:eq(0)");
                if($fa1.hasClass("fa-plus-square-o")){
                    $fa1.addClass("fa-minus-square-o").removeClass("fa-plus-square-o fa-spinner");
                    $fa1.parents(".p").siblings(".childrenDiv").show();
                    $fa1.siblings(".fa2").removeClass("fa-folder").addClass("fa-folder-open");
                    //if($fa1.closest(".childrenDiv").find(".childrenDiv").length==0)
                    if($(this).parent().hasClass("childrenDiv"))
                        getFolio($fa1.attr("data-folioId"),$fa1.closest(".childrenDiv"));
                }else if($fa1.hasClass("fa-minus-square-o")){
                    $fa1.addClass("fa-plus-square-o").removeClass("fa-minus-square-o fa-spinner");
                    $fa1.parents(".p").siblings(".childrenDiv").hide();
                    $fa1.siblings(".fa2").removeClass("fa-folder-open").addClass("fa-folder");
                }
            }).end().on('click',"div.notp",function(){
                //var $tilte=$(this).parents("#folioModal").find(".modal-header>.modal-title").html().trim();
                //var str = $tilte=="移动到"?"无发移动,目标文件夹是源文件的子文件夹":"";
                createMeg("无发移动,目标文件夹是源文件的子文件夹");
            });
            $div.on('click','.fa1',function(){

            });
            $("#creatFolio").click(function(){
                var $active=$(".active-p");
                var parentDir=parseInt($active.parent().attr("data-parentDir"))+1;

                var $children=$('<div class="childrenDiv new" data-parentDir="'+parentDir+'"><div class="p now">'+
                    '<i class="fa fa1"></i> <i class="fa fa2 fa-folder"></i>'+
                    ' <input type="text" name="fileName"><span class="text-center spanOption ok">√</span>'+
                    '<span class="text-center spanOption toHide">×</span>'+
                    '</div></div>');
                $children.find(".p").css("padding-left",parentDir*20+"px");
                $children.find(".toHide").on('click',function(){
                    $children.remove();
                }).end().find(".ok").on('click',function(){
                    var $fileName = $children.find("input[name=fileName]").val();
                    if ($fileName.trim().length == 0) {//确定创建文件夹
                        openModal("文件名不能为空", "<span>好的</span>");
                    } else {
                        var parentDirId = $active.find(".fa1:eq(0)").attr("data-folioid");

                        createFolio($fileName,parentDirId,$children);
                    }
                });
                $active.parent().append($children).find("[name=fileName]").focus();

            })
        });

        function getFolio(parentDir,$el){
            $el.find(".childrenDiv").remove();
            var dir = parseInt($el.attr("data-parentDir"))+1;

            var tarClazz="";
            if($el.find(".fa1").hasClass("fa-plus-square-o")){
                tarClazz="fa-plus-square-o";
            }else if($el.find(".fa1").hasClass("fa-minus-square-o")){
                tarClazz="fa-minus-square-o";
            }
            $.ajax({
                type:"GET",
                url:"rest/folio/getFolio",
                data:"parentDir="+parentDir,
                beforeSend:function(){
                    if(parentDir>0){
                        $el.find(".fa1").addClass("fa-spinner").removeClass("fa-minus-square-o fa-plus-square-o");
                    }else{
                        openSpinner("拼命加载中！！！！");
                    }
                },success:function(data){
                    $.each(data,function(i,obj){
                        var clazz = obj.children>0?'fa-plus-square-o':'';
                        var $children=$('<div class="childrenDiv" data-parentDir="'+dir+'"><div class="p">'+
                            '<i class="fa fa1 '+clazz+'" data-folioId="'+obj.id+'"></i> <i class="fa fa2 fa-folder"></i>'+
                            '<span>'+obj.showName+'</span>'+
                            '</div></div>');
                        $children.find(".p").css("padding-left",dir*20+"px");

                        var $span=$("#folioModal .modal-footer .btn.btn-primary>span"),
                            typeId=$span.attr("filetype").split(","),
                            folioAndFileId=$span.attr("currentfileid").split(","),
                            option=$span.attr("option");

                        $.each(typeId,function(i,obk){
                            if(obk == obj.type && folioAndFileId[i] == obj.id && option=="move"){
                                $children.find("div.p:eq(0)").removeClass("p active").addClass("notp")
                                    .find(".fa1:eq(0)").removeClass("fa-plus-square-o");
                            }
                        });
                        $el.append($children);
                    });
                },error:function(xhr){
                    alert("getFolio错误\n"+xhr.responseTest);
                },complete:function(){
                    if(parentDir>0){
                        $el.find(".fa1:eq(0)").addClass(tarClazz).removeClass("fa-spinner");
                    }else{
                        closeSpinner();
                    }
                }
            });
        }

        //创建文件夹
        function createFolio($fileName,parentdir,target){
            $.ajax({
                url:"/sys/userFile/establishFile",
                type:"POST",
                //contentType:"application/json",
                data:"filename="+$fileName.trim()+"&belong="+parentdir,
                success:function(data){
                    //checkMsg(data.msg,data.status);
                    if(data.code != 1){
                        if(target==null){
                            /*getMyFile(parentdir,null,"timeAsc");*/
                            currentPage = 1;
                            pageSize = 10;
                            $(".page").hide();
                            filename = '';
                            startDate = '';
                            endDate = '';
                            render();
                        }else{
                            var $active = target.siblings("div.p");
                            $active.find(".fa1").removeClass("fa-plus-square-o fa-spinner").addClass("fa-minus-square-o")
                                .end().find(".fa2").removeClass("fa-folder").addClass("fa-folder-open");
                            getFolio($active.find(".fa1").attr("data-folioId"),$active.parent());
                        }
                    }else{
                        layer.alert(data.msg);
                    }
                },complete:function(){
                    closeSpinner();
                }
            });
        }
        function openFolioModal($el,title){
            $("#folioModal").modal("show").find(".modal-footer>.btn.btn-primary").html($el)
                .end().find(".modal-header h5").html(title);
        }
    </script>
    <!-- <button type="button" id="creatFolio" class="btn btn-default">新建文件夹</button>
     <button type="button" class="btn btn-primary" data-dismiss="modal">确定</button>
     <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>-->
</div>

<div id="spinner"><i class="fa fa-spinner" aria-hidden="true"></i>加载中。。。</div>
<script type="text/javascript">
    function createMeg(content){
        var $nav=$("<span>"+content+"</span>");
        $nav.addClass("errmsg");
        var width=40+(content.length*15);
        $nav.css("width",width);
        $("body").append($nav);
        $nav.siblings(".cormsg,.errmsg").remove();
        setTimeout(function(){$nav.fadeOut(300,function(){$nav.remove();});},4500);
    }
    function createCormsg(content){
        var $nav=$("<span>"+content+"</span>");
        $nav.addClass("cormsg");
        $("body").append($nav);
        $nav.siblings(".cormsg,.errmsg").remove();
        setTimeout(function(){$nav.fadeOut(300,function(){$nav.remove();});},2000);
    }
    function checkMsg(content,status){
        var $nav=$("<span>"+content+"</span>");
        var time =2000;
        if(status==200){
            $nav.addClass("cormsg");
            time=4500;
        }else{
            $nav.addClass("errmsg");
        }
        var width=40+(content.length*15);
        $nav.css("width",width);
        $("body").append($nav);
        $nav.siblings(".cormsg,.errmsg").remove();
        setTimeout(function(){$nav.fadeOut(300,function(){$nav.remove();});},time);
    }
    function openSpinner(content){
        content=(content == "undefined" || content.length<1)?"加载中。。。":content;
        $("#spinner").html('<i class="fa fa-spinner"></i>'+content).show();
    }
    function closeSpinner(){
        $("#spinner").hide().html('<i class="fa fa-spinner"></i>加载中。。。');
    }
</script>
<div id="folioModal" class="modal fade" tabindex="11" role="dialog" style="top: 90px;">
    <div class="modal-dialog" role="document" style="width: 500px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h5 class="modal-title">复制到</h5>
            </div>
            <div class="modal-body">
                <div id="folioModalBody">
                    <div data-parentDir="0" class="folioAll childrenDiv">
                        <div class="p active-p" style="border-color: rgb(154, 205, 253);">
                            <i class="fa fa1 fa-minus-square-o" data-folioid="0"></i>
                            <i class="fa fa2 fa-folder-open"></i>
                            <span>全部文件</span>
                            <!--<i class="fa fa-plus-square-o" aria-hidden="true"></i>+
                            <i class="fa fa-minus-square-o" aria-hidden="true"></i>-
                            <i class="fa fa-spinner" aria-hidden="true"></i>0
                            <i class="fa fa-folder"></i>
                            <i class="fa fa-folder-open" aria-hidden="true"></i>-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="showShareFileInfo" class="modal fade" data-backdrop="static">
    <div class="modal-dialog" style="margin-top: 100px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">文件信息</h4>
            </div>
            <div class="modal-body" style="padding: 30px 0;text-align: center;">
                <div class="settingInfo clearfix" style="max-height: 174px;overflow: auto;">
                    <style>
                        #shareFileInfo .fa{font-size: 20px;margin:0 10px;}
                        #shareFileInfo .fa-folder{color: #ffd65a;}
                        #shareFileInfo .fa-file-audio-o{color: #8284f1;}
                        #shareFileInfo .fa-file-audio-o{color: #8284f1;}
                        #shareFileInfo .fa-file-image-o{color: #ff7844;}
                        #shareFileInfo .fa.fa-file{color: #64c424;}
                        #shareFileInfo tr{height: 32px;box-sizing: border-box;}
                        #shareFileInfo tr:first-of-type td{border-top: 1px solid #ccc;}
                        #shareFileInfo tr td{border-bottom: 1px solid #ccc;}
                    </style>
                    <table style="width: 80%;margin: 0 10%;text-align: left;" cellspacing="0">
                        <thead>
                        <tr style="height: 45px;">
                            <th width="80%"><span>文件名</span></th>
                            <th width="20%"><span>大小</span></th>
                        </tr>
                        </thead>
                        <tbody id="shareFileInfo">
                        <script type="text/javascript">
                            function showShareFileInfo(fileShareId){
                                $("#showShareFileInfo").modal("show");
                                var shareFileInfo = $("#shareFileInfo");
                                shareFileInfo.empty();
                                $.ajax({
                                    type:"GET",
                                    url:"rest/fileShare/showShareFileInfo/"+fileShareId,
                                    beforeSend:function(){
                                        openSpinner("正在打开分享文件记录中哦。。");
                                    },complete:function(){
                                        closeSpinner();
                                    },error:function(xhr){
                                        alert("查看分享文件记录错误\n"+xhr.responseText);
                                    },success:function(data){
                                        $.each(data,function(i,obj){
                                            var $tr = $("<tr data-id='"+obj.id+"' data-type='"+1+"' data-parentDir='"+obj.parentDir+"'>"+
                                                "<td width='80%'><i class='fa "+obj.clazz+"'></i>" +
                                                "<span>" + obj.showName + "</span></td>" +
                                                "<td width='20%'>" + obj.size + "</td></tr>");
                                            shareFileInfo.append($tr);
                                        });
                                    }
                                });

                            }
                        </script>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="modal-footer" style="margin: 10px 15px 10px;">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("#bs-example-navbar-collapse-1>ul:eq(0)>li:eq(0)").addClass("active").siblings("li").removeClass("active");
    });

    //发送文件
    function sendFile() {
        if ($(".headerTr~tr td [name=ck]:checked").length == 0) {
            layer.msg("请选择文件");
            return;
        }
        var $trs = $(".headerTr~tr td [name=ck]:checked").closest("tr");
        var fileId=[];
        $.each($trs,function(i,obj){
            var isFolder = $(obj).attr("data-title");
            if(isFolder == 1) {
                layer.msg("文件夹不可发送");
                return;
            }else {
                fileId.push($(obj).attr("data-id"));
            }
        });
        if(null != fileId && fileId.length == $(".headerTr~tr td [name=ck]:checked").length) {

            //ajax判断文件是否可以发送
            $.ajax({
                url : "/sys/userFile/judeSend",
                type : "post",
                data : {
                    'ids' : fileId
                },
                success : function(r) {
                    if (r.code==0) {
                        layer.open({
                            type : 2,
                            title : '文件发送',
                            shadeClose : false, // 点击遮罩关闭层
                            area : [ '100%', '100%' ],
                            content : '/sys/userFile/toBatchSend?ids='+fileId // iframe的url
                        });
                    }else{
                        layer.msg(r.msg);
                    }
                }
            });
        }
    }

    //删除文件
    function deleteFile() {
        if ($(".headerTr~tr td [name=ck]:checked").length == 0) {
            layer.msg("请选择文件");
            return;
        }
        var $trs = $(".headerTr~tr td [name=ck]:checked").closest("tr");
        var fileId=[];
        $.each($trs,function(i,obj){
            fileId.push($(obj).attr("data-id"));
        });
        //判断文件是否可以删除（文件夹下有文件不可删除）
        $.ajax({
            url : "/sys/userFile/judeDeleteFile",
            type : "post",
            data : {
                'ids' : fileId
            },
            success : function(r) {
                if (r.code==0) {
                    layer.confirm("确认要删除数据吗?", {
                        btn : [ '确定', '取消' ]
                        // 按钮
                    }, function() {
                        $.ajax({
                            url : "/sys/userFile/deleteFile",
                            type : "post",
                            data : {
                                'ids' : fileId
                            },
                            success : function(r) {
                                if (r.code==0) {
                                    layer.msg("操作成功");
                                    currentPage = 1;
                                    pageSize = 10;
                                    $(".page").hide();
                                    filename = '';
                                    startDate = '';
                                    endDate = '';
                                    render();
                                }else{
                                    layer.msg(r.msg);
                                }
                            }
                        });
                    })
                }else{
                    layer.msg(r.msg);
                    return false;
                }
            }
        });
    }

    //下载文件
    function downloadFile() {
        if ($(".headerTr~tr td [name=ck]:checked").length != 1) {
            layer.msg("请选择一个文件");
            return;
        }
        var $trs = $(".headerTr~tr td [name=ck]:checked").closest("tr");
        var fileId=[];
        $.each($trs,function(i,obj){
            var isFolder = $(obj).attr("data-title");
            if(isFolder == 1) {
                layer.msg("文件夹不可下载");
                return;
            }else {
                fileId.push($(obj).attr("data-id"));
            }
        });
    }

</script>

<div class="uploadBox">
    <div class="uploadBoxMin">
        <div class="clearUplaod">×</div>
        <form method="post" id="myForm" action="/fileTest.php" enctype="multipart/form-data">
            <!-- 上传的文件列表 -->
            <table id="upload-list">
                <thead>
                    <tr>
                        <th width="20%">文件名</th>
                        <th width="15%">文件类型</th>
                        <th width="15%">文件大小</th>
                        <th width="20%">上传进度</th>
                        <th width="15%">
                            <input type="button" id="pause-all-btn"  value="暂停">
                        </th>
                        <th width="15%">
                            <input type="button" id="cancel-all-btn" value="全部取消">
                        </th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
            <div class="upload-foot">
                <input type="button" id="upload-all-btn" value="上传">
                <input type="button" class="closeUpload" value="关闭">
            </div>
        </form>
    </div>
</div>


<!-- 上传文件列表中每个文件的信息模版 -->
<script type="text/template" id="file-upload-tpl">
    <tr>
        <td>{{fileName}}</td>
        <td>{{fileType}}</td>
        <td>{{fileSize}}</td>
        <td class="upload-progress">{{progress}}</td>
        <td>
            <div class="upload-item-btn" data-name="{{fileName}}" data-size="{{totalSize}}" data-filemd5="{{fileMd5}}" data-state="default">
                {{uploadVal}}
            </div>
        </td>
        <td>
            <!--<input type="button" class="cancel-item-btn" data-name="{{fileName}}" data-size="{{totalSize}}" data-state="default" value="取消上传">-->
            <img class="cancel-item-btn" data-name="{{fileName}}" data-size="{{totalSize}}" data-filemd5="{{fileMd5}}" data-state="default"
                 src="../../img/upload/cancel.png" />
        </td>
    </tr>
</script>
<style type="text/css">
    body {
        font-family: Arial;
    }

    .uploadBox form {
        margin: 50px auto;
    }

    .uploadBox table {
        width: 100%;
        display: none;
        margin-top: 15px;
        border: 1px solid #ddd;
        border-collapse: collapse;
    }

    .uploadBox table th {
        color: #666;
    }

    .uploadBox table td,
    .uploadBox table th {
        padding: 5px;
        border: 1px solid #ddd;
        text-align: center;
        font-size: 12px;
    }

    /*#layui-layer-shade2,#layui-layer2{
        display: none;
    }*/

    .uploadBox input[type="button"] {
        background: #3b8cff;
        padding: 5px 10px;
        color: #fff;
        font-weight: 500;
        cursor: pointer;
        border: none;
        border-radius: 4px;
    }

    #upload-list img{
        height: 18px;
    }

    .upload-foot{
        margin-top: 30px;
        text-align: center;
    }

    .upload-foot input{
        margin: 0 10px;
        display: inline-block;
        background: #3b8cff;
        padding: 5px 10px;
        color: #fff;
        font-weight: 500;
        cursor: pointer;
        border: none;
        border-radius: 4px;
    }
</style>
<script type="text/javascript">
    // 全部上传操作
    $(document).on('click', '#upload-all-btn', function() {
        // 未选择文件
        if (!$('#myFile2').val()) {
            $('#myFile2').focus();
        }
        // 模拟点击其他可上传的文件
        else {
            $('#upload-list .upload-item-btn').each(function() {
                $(this).click();
            });
        }
    });

    function get_filemd5sum(ofile) {
        const result = new Promise((resolve, reject) => {
            var fileReader = new FileReader();
            var file = ofile;
            var tmp_md5;
            var fileMd5All;
            var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,
                // file = this.files[0],
                chunkSize = 10 * 1024 * 1024, // Read in chunks of 10MB
                chunks = Math.ceil(file.size / chunkSize),
                currentChunk = 0,
                spark = new SparkMD5.ArrayBuffer();
            frOnload = function(e) {
                // console.log('read chunk nr', currentChunk + 1, 'of', chunks);
                spark.append(e.target.result); // Append array buffer
                currentChunk++;
                var md5_progress = Math.floor((currentChunk / chunks) * 100);

                console.log(file.name + "  正在处理，请稍等," + "已完成" + md5_progress + "%");
                if (currentChunk < chunks) {
                    loadNext();
                } else {
                    tmp_md5 = spark.end();
                    fileMd5All = tmp_md5;
                    console.log("文件md5值:",fileMd5All)
                    resolve(fileMd5All)
                }
            };
            frOnerror = function() {
                console.warn('oops, something went wrong.');
                reject('oops, something went wrong.');
            };

            fileReader.onload = frOnload;
            fileReader.onerror = frOnerror;

            function loadNext() {
                var start = currentChunk * chunkSize,
                    end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
                fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
            }
            loadNext()
        })
        return result
    }

    // 选择文件-显示文件信息
    $('#myFile2').change(async function(e) {
        var file,
            uploadItem = [],
            uploadItemTpl = $('#file-upload-tpl').html(),
            size,
            percent,
            progress = '未上传',
            //uploadVal = '开始上传';
            uploadVal = '<img src="../../img/upload/pause.png" />',
            fileMd5;
        //根据上传文件类型的黑白名单判断文件是否能上传
        if(nameListOn == "1") {
            //开启名单
            //白名单
            if(nameListType == "1") {
                if(whiteNameList == "" || whiteNameList == null) {
                    layer.msg("暂无允许上传的文件类型");
                    return false;
                }else {
                    var array1 = whiteNameList.split(",");
                    for (var i = 0, j = this.files.length; i < j; ++i) {
                        var file1 = this.files[i];
                        var fileType1 = file1.name.substring(file1.name.lastIndexOf(".") + 1, file1.name.length);
                        if(array1.indexOf(fileType1) == -1) {
                            layer.msg(fileType1 + "类型文件不允许上传");
                            return false;
                        }
                    }
                }
            }
            //黑名单
            if(nameListType == "2") {
                if(blackNameList != "" && blackNameList != null) {
                    var array2 = blackNameList.split(",");
                    for (var i = 0, j = this.files.length; i < j; ++i) {
                        var file1 = this.files[i];
                        var fileType1 = file1.name.substring(file1.name.lastIndexOf(".") + 1, file1.name.length);
                        if(array2.indexOf(fileType1) > -1) {
                            layer.msg(fileType1 + "类型文件不允许上传");
                            return false;
                        }
                    }
                }
            }
        }
        for (var i = 0, j = this.files.length; i < j; ++i) {
            file = this.files[i];
            //计算文件MD5值
            percent = undefined;
            progress = '未上传';
            //uploadVal = '开始上传';
            uploadVal = '<img src="../../img/upload/pause.png" />';
            // 计算文件大小
            size = file.size > 1024 ?
                file.size / 1024 > 1024 ?
                    file.size / (1024 * 1024) > 1024 ?
                        (file.size / (1024 * 1024 * 1024)).toFixed(2) + 'G' :
                        (file.size / (1024 * 1024)).toFixed(2) + 'M' :
                    (file.size / 1024).toFixed(2) + 'KB' :
                (file.size).toFixed(2) + 'B';
            // 初始通过本地记录，判断该文件是否曾经上传过
            percent = window.localStorage.getItem(file.name + '_p');
            if (percent && percent !== '100.0' && percent !== '100') {
                progress = '已上传 ' + percent + '%';
                //uploadVal = '继续上传';
                //uploadVal = '<img src="../../img/upload/pause.png" />'
            }

            fileMd5 = await get_filemd5sum(file);
            // 更新文件信息列表
            uploadItem.push(uploadItemTpl
                .replace(/{{fileName}}/g, file.name)
                /*.replace('{{fileType}}', file.type || file.name.match(/\.\w+$/) + '文件')*/
                .replace('{{fileType}}', file.name.substring(file.name.lastIndexOf(".") + 1, file.name.length))
                .replace('{{fileSize}}', size)
                .replace('{{progress}}', progress)
                .replace('{{totalSize}}', file.size)
                .replace('{{uploadVal}}', uploadVal)
                .replace('{{fileMd5}}', fileMd5)
            );
        }
        $(".uploadBox").show();
        $('#upload-list').children('tbody').html(uploadItem.join(''))
            .end().show();
        $('#upload-all-btn').val('上传').prop('disabled', false).css('cursor', 'pointer');
    });
    /**
     * 上传文件时，提取相应匹配的文件项
     * @param {String} fileName 需要匹配的文件名
     * @return {FileList} 匹配的文件项目
     */
    function findTheFile(fileName) {
        var files = $('#myFile2')[0].files,
            theFile;
        for (var i = 0, j = files.length; i < j; ++i) {
            if (files[i].name === fileName) {
                theFile = files[i];
                break;
            }
        }
        return theFile ? theFile : [];
    }
    // 取消上传
    $(document).on('click', '.cancel-item-btn', function() {
        //$(this).parents('tr').remove();
        let fileName =  "";
        fileName += $(this).attr('data-name') + ",";
        removeItem(fileName,$(this).parents("tr").index())
    })

    $(document).on('click', '#cancel-all-btn', function() {
        /*let fileName = [];
        for (var i=0; i<$(".cancel-item-btn").length; i++){
            fileName.push($(".cancel-item-btn").eq(i).attr('data-name'))
        }
        removeItem(fileName,'-1')*/
        let fileName = "";
        for (var i=0; i<$(".cancel-item-btn").length; i++){
            fileName += $(".cancel-item-btn").eq(i).attr('data-name') + ",";
        }
        removeItem(fileName,'-1')
    })

    //暂停上传
    var isFirst = 1;
    $(document).on('click', '#pause-all-btn', function() {
        // 第一次点击上传
        if(isPaused == 0 && isFirst == 0) {
            $('#upload-all-btn').click();
        }
    })

    var islocal = 0;
    var localName = '';
    var localNameChunk = '';
    function removeItem(fileNameList,index){
        if(index == -1){
            islocal = 2
            //$('#upload-all-btn').click();
            // 第一次点击上传
            if(isPaused == 0 && isFirst == 0) {
                $('#upload-all-btn').click();
            }
            $("#upload-list tbody").html('');
            window.localStorage.clear();
            $.ajax({
                type: 'post',
                url: '/sys/userFile/cancelUploadFile',
                data: {"fileNames": fileNameList},
                success: function (rs) {

                }
            });
        }else {
            islocal = 1;
            localName = $('.cancel-item-btn').eq(index).attr('data-name') + '_p';
            localNameChunk = $('.cancel-item-btn').eq(index).attr('data-name') + '_chunk';
            //$(".upload-item-btn").eq(index).click();
            // 第一次点击上传
            // if(isPaused == 0 && isFirst == 0) {
            //     $(".upload-item-btn").eq(index).click();
            // }
            $('.cancel-item-btn').eq(index).parents('tr').remove();
            window.localStorage.removeItem(localName);
            window.localStorage.removeItem(localNameChunk);
            $.ajax({
                type: 'post',
                url: '/sys/userFile/cancelUploadFile',
                data: {"fileNames": fileNameList},
                success: function (rs) {

                }
            });
        }
        $("#myFile2").val("");
    }

    // 暂停上传操作
    var isPaused = 0;
    // 上传文件
    $(document).on('click', '.upload-item-btn', function() {
        isFirst = 0;
        var $this = $(this),
            state = $this.attr('data-state'),
            msg = {
                done: '上传成功',
                failed: '上传失败',
                in: '上传中...',
                paused: '暂停中...',
                quick: '极速秒传',
            },
            fileName = $this.attr('data-name'),
            $progress = $this.closest('tr').find('.upload-progress'),
            eachSize = 1024 * 1024 * 3,
            totalSize = $this.attr('data-size'),
            chunks = Math.ceil(totalSize / eachSize),
            percent,
            chunk,
            fileMd5 = $this.attr('data-filemd5');

        // 进行暂停上传操作
        // 未实现，这里通过动态的设置isPaused值并不能阻止下方ajax请求的调用
        if (state === 'uploading') {
            //$this.val('继续上传').attr('data-state', 'paused');
            $this.find('img').attr('src','../../img/upload/pause.png')
            $this.attr('data-state', 'paused');
            $progress.text(msg['paused'] + percent + '%');
            isPaused = 1;
            isFirst = 1;
        }else if (state === 'paused' || state === 'default') {
            // 进行开始/继续上传操作
            //$this.val('暂停上传').attr('data-state', 'uploading');
            $this.find('img').attr('src','../../img/upload/start.png')
            $this.attr('data-state', 'uploading');
            isPaused = 0;
            isFirst = 0;
            // 第一次点击上传
            startUpload('first');
        }

        // 上传操作 times: 第几次
        function startUpload(times) {
            // 上传之前查询是否以及上传过分片
            chunk = window.localStorage.getItem(fileName + '_chunk') || 0;
            chunk = parseInt(chunk, 10);
            // 判断是否为末分片
            var isLastChunk = (chunk == (chunks - 1) ? 1 : 0);
            // 如果第一次上传就为末分片，即文件已经上传完成，则重新覆盖上传
            /*if (times === 'first' && isLastChunk === 1) {
                window.localStorage.setItem(fileName + '_chunk', 0);
                chunk = 0;
                isLastChunk = 0;
            }*/
            // 设置分片的开始结尾
            var blobFrom = chunk * eachSize; // 分段开始
            var blobTo = (chunk + 1) * eachSize > totalSize ? totalSize : (chunk + 1) * eachSize; // 分段结尾
            var percent = 0
            if(totalSize == 0) {
                percent = 100.0;
                isLastChunk = 1;
                chunks = 1;
            }else {
                percent = (100 * blobTo / totalSize).toFixed(1); // 已上传的百分比
            }
            //timeout = 5000, // 超时时间
            var fd = new FormData($('#myForm')[0]);
            fd.append('theFile', findTheFile(fileName).slice(blobFrom, blobTo)); // 分好段的文件
            fd.append('fileName', fileName); // 文件名
            fd.append('totalSize', totalSize); // 文件总大小
            fd.append('isLastChunk', isLastChunk); // 是否为末段
            fd.append('isFirstUpload', times === 'first' ? 1 : 0); // 是否是第一段（第一次上传）
            fd.append('chunk', chunk);
            fd.append('chunks', chunks);
            fd.append('belong',belong);
            fd.append('filemd5',fileMd5);
            console.log("chunk值为" + chunk);
            console.log("chunks值为" + chunks);
            // 上传
            $.ajax({
                type: 'post',
                url: '/sys/userFile/uploadFileFor',
                data: fd,
                processData: false,
                contentType: false,
                //timeout: timeout,
                success: function(rs) {
                    // 上传成功
                    if (rs.code === 0) {
                        if(!isClose) {
                            $(".layui-layer-shade,.layui-layer").hide();
                        }
                        // 记录已经上传的百分比
                        window.localStorage.setItem(fileName + '_p', percent);
                        // 已经上传完毕
                        if (chunk === (chunks - 1)) {
                            $progress.text(msg['done']);
                            //$this.val('已经上传').prop('disabled', true).css('cursor', 'not-allowed');
                            $this.find('img').attr('src','../../img/upload/success.png')
                            $this.prop('disabled', true).css('cursor', 'not-allowed');
                            /*if (!$('#upload-list').find('.upload-item-btn:not(:disabled)').length) {
                                $('#upload-all-btn').val('已经上传').prop('disabled', true).css('cursor', 'not-allowed');
                                //$this.attr('data-state', 'uploading');
                            }*/
                            currentPage = 1;
                            pageSize = 10;
                            filename = '';
                            startDate = '';
                            endDate = '';
                            render();
                        } else {
                            // 记录已经上传的分片
                            window.localStorage.setItem(fileName + '_chunk', ++chunk);
                            $progress.text(msg['in'] + percent + '%');
                            // 这样设置可以暂停，但点击后动态的设置就暂停不了..
                            // if (chunk == 10) {
                            // isPaused = 1;
                            // }
                            if (!isPaused) {
                                startUpload();
                            }
                        }
                    }else if (rs.code === 2) {
                        $progress.text(msg['quick']);
                        //$this.val('已经上传').prop('disabled', true).css('cursor', 'not-allowed');
                        $this.find('img').attr('src','../../img/upload/success.png')
                        $this.prop('disabled', true).css('cursor', 'not-allowed');
                        /*if (!$('#upload-list').find('.upload-item-btn:not(:disabled)').length) {
                            $('#upload-all-btn').val('已经上传').prop('disabled', true).css('cursor', 'not-allowed');
                        }*/
                        currentPage = 1;
                        pageSize = 10;
                        filename = '';
                        startDate = '';
                        endDate = '';
                        render();
                    }else if (rs.code === 1) {
                        // 上传失败，上传失败分很多种情况，具体按实际来设置
                        $progress.text(msg[rs.msg]);
                    }
                    /*if(islocal == 1){
                        window.localStorage.removeItem(localName);
                        window.localStorage.removeItem(localNameChunk);
                    }else if(islocal == 2){
                        window.localStorage.clear()
                    }*/
                },
                error: function(rs) {
                    $progress.text(msg[rs.ms]);
                }
            });
        }
    });
</script>

<script>
    //查询，搜索
    //init 时间控件
    $('.input-daterange').datepicker({
        autoclose: true,
        todayBtn: "linked"
    });

    //重置
    function reSet(){
        currentPage = 1;
        pageSize = 10;
        filename = '';
        startDate = '';
        endDate = '';
        $("#filename").val("");
        $("#startDate").val("");
        $("#endDate").val("");
        render();
    }

    //查询
    function reLoad() {
        currentPage = 1;
        pageSize = 10;
        filename = $("#filename").val();
        startDate = $("#startDate").val();
        endDate = $("#endDate").val();
        $(".page").hide();
        render();
    }
</script>

</body>
</html>